#!/bin/bash

# Setup script for Unison service environment variables

echo "Setting up Unison service environment variables..."

# Check if config.env exists
if [ ! -f "config.env" ]; then
    echo "❌ config.env file not found!"
    echo "Please ensure config.env exists in the current directory."
    exit 1
fi

echo "✅ Found config.env file"

# Check if .env already exists
if [ -f ".env" ]; then
    echo "⚠️  .env file already exists!"
    read -p "Do you want to overwrite it? (y/N): " -n 1 -r
    echo
    if [[ ! $REPLY =~ ^[Yy]$ ]]; then
        echo "❌ Setup cancelled."
        exit 1
    fi
fi

# Copy config.env to .env
cp config.env .env
echo "✅ Created .env file from config.env"

# Check if running in Docker
if [ -f "/.dockerenv" ]; then
    echo "🐳 Running in Docker container - using config.env directly"
    echo "✅ Environment variables are loaded from config.env"
else
    echo "🖥️  Running locally - .env file created"
    echo "📝 You can edit .env file if you need to override any settings"
fi

echo "🎉 Environment setup complete!"
echo "📋 Configuration includes:"
echo "   - Service URLs for tech-stack-selector and template-manager"
echo "   - Claude AI API key and configuration"
echo "   - Database connections (PostgreSQL, Neo4j, Redis, MongoDB)"
echo "   - Security and authentication settings"
echo "   - Email configuration"
echo "   - CORS settings"
echo ""
echo "🚀 Next steps:"
echo "   1. Run: npm start"
echo "   2. Or with Docker: docker-compose up -d unison"
