#!/bin/bash
# Wakelai Voice AI Platform - Full Setup Script
# This script installs OpenVoiceUI and sets up the complete SaaS platform

set -e

echo "=========================================="
echo "Wakelai Voice AI Platform Setup"
echo "=========================================="
echo ""

# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

PROJECT_DIR="/home/ashraffarid2010/wakelai.com"
cd "$PROJECT_DIR"

# Check prerequisites
echo "Checking prerequisites..."

if ! command -v docker &> /dev/null; then
    echo -e "${YELLOW}Warning: Docker not found. OpenVoiceUI requires Docker.${NC}"
fi

if ! command -v python3 &> /dev/null; then
    echo "Error: Python 3 not found"
    exit 1
fi

if ! command -v psql &> /dev/null; then
    echo "Error: PostgreSQL not found"
    exit 1
fi

echo -e "${GREEN}✓ Prerequisites check complete${NC}"
echo ""

# Install Python dependencies
echo "Installing Python dependencies..."
pip3 install -r requirements.txt

echo -e "${GREEN}✓ Python dependencies installed${NC}"
echo ""

# Initialize database
echo "Initializing database..."
bash scripts/init_db.sh

echo -e "${GREEN}✓ Database initialized${NC}"
echo ""

# Create logs directory
mkdir -p logs

# Copy .env.example if .env doesn't exist
if [ ! -f .env ]; then
    echo "Creating .env file from .env.example..."
    cp .env.example .env
    echo -e "${YELLOW}Please edit .env with your configuration values${NC}"
fi

echo ""
echo "=========================================="
echo -e "${GREEN}Setup Complete!${NC}"
echo "=========================================="
echo ""
echo "Next steps:"
echo "1. Edit .env with your API keys and configuration"
echo "2. Create admin user: python run.py create-admin"
echo "3. Start the server: python run.py"
echo ""
echo "The platform will be available at:"
echo "  http://localhost:4000"
echo ""
