#!/bin/bash

# ============================================
# Miku Discord Bot - Setup Script
# ============================================
# This script helps you set up the configuration

set -e

echo "🎵 Miku Discord Bot - Configuration Setup"
echo "========================================"
echo ""

# Check if .env exists
if [ -f ".env" ]; then
    echo "⚠️  .env file already exists."
    read -p "Do you want to backup it and create a new one? (y/N): " -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        mv .env .env.backup.$(date +%Y%m%d_%H%M%S)
        echo "✅ Old .env backed up"
    else
        echo "❌ Setup cancelled. Using existing .env"
        exit 0
    fi
fi

# Copy .env.example to .env
if [ -f ".env.example" ]; then
    cp .env.example .env
    echo "✅ Created .env from .env.example"
else
    echo "❌ .env.example not found!"
    exit 1
fi

echo ""
echo "📝 Please edit .env and add your values:"
echo "   - DISCORD_BOT_TOKEN (required)"
echo "   - OWNER_USER_ID (optional, defaults to existing value)"
echo "   - ERROR_WEBHOOK_URL (optional)"
echo ""

# Check if config.yaml exists
if [ ! -f "config.yaml" ]; then
    echo "❌ config.yaml not found!"
    echo "   This file should have been created with the config system."
    exit 1
else
    echo "✅ config.yaml found"
fi

echo ""
echo "📚 Next steps:"
echo "   1. Edit .env and add your API keys and tokens"
echo "   2. (Optional) Edit config.yaml to customize settings"
echo "   3. Run: docker compose up -d"
echo ""
echo "✅ Setup complete!"
