#!/bin/bash

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

echo "Starting SamCloud Music application..."
echo "Script directory: $SCRIPT_DIR"

# Load environment variables from .env file
if [ -f "$SCRIPT_DIR/.env" ]; then
    echo "Loading environment variables from .env file..."
    export $(grep -v '^#' "$SCRIPT_DIR/.env" | xargs)
else
    echo "Warning: .env file not found in $SCRIPT_DIR"
fi

# Set the Python path to include the project root
export PYTHONPATH="$SCRIPT_DIR:$PYTHONPATH"
echo "PYTHONPATH set to: $PYTHONPATH"

# Verify Spotify credentials are set
echo "Verifying Spotify credentials..."
echo "CLIENT_ID: ${CLIENT_ID:0:5}..."
echo "CLIENT_SECRET: ${CLIENT_SECRET:0:5}..."

# Change to the backend directory
cd "$SCRIPT_DIR/backend"

# Run the application with environment variables
echo "Starting Flask application..."
python -m spotspot
