#!/bin/bash
# Build script for SecondVoice

set -e

# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color

echo "SecondVoice Build Script"
echo "======================="
echo ""

# Check if vcpkg is set
if [ -z "$VCPKG_ROOT" ]; then
    echo -e "${RED}Error: VCPKG_ROOT not set${NC}"
    echo "Please install vcpkg and set VCPKG_ROOT environment variable:"
    echo "  git clone https://github.com/microsoft/vcpkg.git"
    echo "  cd vcpkg && ./bootstrap-vcpkg.sh"
    echo "  export VCPKG_ROOT=\$(pwd)"
    exit 1
fi

echo -e "${GREEN}vcpkg found at: $VCPKG_ROOT${NC}"
echo ""

# Check if .env exists
if [ ! -f ".env" ]; then
    echo -e "${RED}Warning: .env file not found${NC}"
    echo "Please create .env from .env.example and add your API keys"
    echo "  cp .env.example .env"
    echo ""
fi

# Configure
echo "Configuring CMake..."
cmake -B build -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake

# Build
echo ""
echo "Building..."
cmake --build build -j$(nproc)

echo ""
echo -e "${GREEN}Build successful!${NC}"
echo ""
echo "To run the application:"
echo "  cd build"
echo "  ./SecondVoice"
