#!/bin/bash

set -e

echo "🚀 Setting up Suno Alfred Plugins..."

# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"

# Install Python dependencies
echo "📦 Installing Python dependencies..."
uv sync

# Create Alfred workflow symlink
ALFRED_WORKFLOWS_DIR="$HOME/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows"
WORKFLOW_LINK="$ALFRED_WORKFLOWS_DIR/suno-alfred"

if [ ! -d "$ALFRED_WORKFLOWS_DIR" ]; then
    echo "❌ Alfred workflows directory not found. Make sure Alfred is installed."
    exit 1
fi

if [ -L "$WORKFLOW_LINK" ]; then
    echo "🔗 Alfred workflow symlink already exists"
elif [ -e "$WORKFLOW_LINK" ]; then
    echo "❌ $WORKFLOW_LINK already exists but is not a symlink"
    echo "Please remove it manually and run setup again"
    exit 1
else
    echo "🔗 Creating Alfred workflow symlink..."
    ln -sf "$SCRIPT_DIR" "$WORKFLOW_LINK"
fi

echo ""
echo "✅ Setup complete!"
echo "" Open the workflow in Alfred preferences and configure the environment variables.