#!/bin/bash

# Geek-Life v2.0 Build Script
# Builds multi-tenant version with PostgreSQL support

set -e

VERSION="2.0.0"
APP_NAME="geek-life"
BUILD_DIR="builds"

echo "Building Geek-Life v${VERSION} with multi-tenant support..."

# Create build directory
mkdir -p ${BUILD_DIR}

# Clean previous builds
rm -f ${BUILD_DIR}/${APP_NAME}_v2_*

# Build for different platforms
echo "Building for Linux (amd64)..."
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=${VERSION}" -o ${BUILD_DIR}/${APP_NAME}_v2_linux-amd64 app/*.go

echo "Building for Linux (arm64)..."
GOOS=linux GOARCH=arm64 go build -ldflags "-X main.version=${VERSION}" -o ${BUILD_DIR}/${APP_NAME}_v2_linux-arm64 app/*.go

echo "Building for macOS (amd64)..."
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=${VERSION}" -o ${BUILD_DIR}/${APP_NAME}_v2_darwin-amd64 app/*.go

echo "Building for macOS (arm64)..."
GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.version=${VERSION}" -o ${BUILD_DIR}/${APP_NAME}_v2_darwin-arm64 app/*.go

echo "Building for Windows (amd64)..."
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=${VERSION}" -o ${BUILD_DIR}/${APP_NAME}_v2_windows-amd64.exe app/*.go

echo "Building for Windows (arm64)..."
GOOS=windows GOARCH=arm64 go build -ldflags "-X main.version=${VERSION}" -o ${BUILD_DIR}/${APP_NAME}_v2_windows-arm64.exe app/*.go

echo "Build completed! Binaries are in the ${BUILD_DIR} directory:"
ls -la ${BUILD_DIR}/${APP_NAME}_v2_*

echo ""
echo "To run the application:"
echo "1. Set up PostgreSQL database"
echo "2. Copy .env.example to .env and configure"
echo "3. Run migrations: ./${APP_NAME}_v2_* --migrate"
echo "4. Start the application: ./${APP_NAME}_v2_*"