#!/bin/bash

# Setup script for installing Skilled Feishu MCP in Cherry Studio
echo "Setting up Skilled Feishu MCP for Cherry Studio..."

# Get the current directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CONFIG_FILE="$SCRIPT_DIR/cherry-studio-config.json"

# Check if configuration file exists
if [ ! -f "$CONFIG_FILE" ]; then
    echo "Error: cherry-studio-config.json not found in the same directory as this script"
    exit 1
fi

# Create .env file for development if it doesn't exist
if [ ! -f "$SCRIPT_DIR/.env" ]; then
    echo "Creating development .env file..."
    cat > "$SCRIPT_DIR/.env" << EOF
NODE_ENV=development
FEISHU_APP_ID=cli_test_9e11c52b0e1c500e
FEISHU_APP_SECRET=test_app_secret_for_development
EOF
    echo ".env file created with development settings"
else
    echo ".env file already exists, skipping creation"
fi

# Install dependencies if node_modules doesn't exist
if [ ! -d "$SCRIPT_DIR/node_modules" ]; then
    echo "Installing dependencies..."
    npm install
else
    echo "Dependencies already installed, skipping npm install"
fi

# Build the project
echo "Building the project..."
npm run build

echo ""
echo "==================================================="
echo "Setup complete! To add this MCP server to Cherry Studio:"
echo ""
echo "1. Open Cherry Studio"
echo "2. Go to Settings > Tools > MCP Tool Providers"
echo "3. Click 'Add MCP Tool Provider'"
echo "4. Select 'Install from local folder'"
echo "5. Choose this directory: $SCRIPT_DIR"
echo "6. Cherry Studio will use cherry-studio-config.json to set up the connection"
echo "7. You should now see 'Skilled Feishu MCP' in your list of available tool providers"
echo "==================================================="
echo ""
echo "If you need to provide different Feishu credentials:"
echo "1. Edit the .env file in this directory"
echo "2. Replace the test credentials with your actual Feishu App ID and App Secret"
echo "" 