#!/bin/bash

# Specify only Windows architecture
ARCHITECTURES=("windows/amd64")
PROJECT_NAME=$(basename "$(pwd)")

prepare_build() {
    mkdir -p dist build_logs
    if [ ! -f go.mod ]; then
        go mod init "$PROJECT_NAME"
    fi
    go mod tidy
}

build_binary() {
    local os=$1
    local arch=$2
    local output="dist/${PROJECT_NAME}_${os}_${arch}.exe" # Note the .exe for Windows
    env GOOS=$os GOARCH=$arch go build -o $output . &> "build_logs/${os}_${arch}.log"
    if [ $? -ne 0 ]; then
        echo "Build failed for $os/$arch" >> "build_logs/error.log"
    else
        echo "Build succeeded for $os/$arch"
    fi
}

main() {
    prepare_build
    for arch in "${ARCHITECTURES[@]}"; do
        IFS="/" read -r os arch <<< "$arch"
        build_binary $os $arch
    done
    echo "Build process completed."
}

main
