#!/bin/bash
# Wrapper script to run AISSIA with .env loaded

set -e

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

# Check if .env exists
if [ ! -f .env ]; then
    echo -e "${YELLOW}Warning: .env file not found. Create one with ANTHROPIC_API_KEY${NC}"
    exit 1
fi

# Load .env
echo -e "${GREEN}Loading .env...${NC}"
set -a
source .env
set +a

# Check if API key is set
if [ -z "$ANTHROPIC_API_KEY" ]; then
    echo -e "${YELLOW}Warning: ANTHROPIC_API_KEY not set in .env${NC}"
    exit 1
fi

# Check if binary exists
if [ ! -f ./build/aissia ]; then
    echo -e "${YELLOW}Error: ./build/aissia not found. Run: cmake --build build${NC}"
    exit 1
fi

# Run AISSIA with provided arguments (default to interactive mode)
if [ $# -eq 0 ]; then
    echo -e "${GREEN}Starting AISSIA in interactive mode...${NC}"
    ./build/aissia -i
else
    ./build/aissia "$@"
fi
