#!/bin/bash
set -e

echo "🔨 Building Slack to ntfy middleware..."

# Build for different platforms
PLATFORMS="linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64"
OUTPUT_DIR="dist"

mkdir -p $OUTPUT_DIR

for platform in $PLATFORMS; do
    OS=$(echo $platform | cut -d'/' -f1)
    ARCH=$(echo $platform | cut -d'/' -f2)
    
    OUTPUT_NAME="middleware-$OS-$ARCH"
    if [ $OS = "windows" ]; then
        OUTPUT_NAME="$OUTPUT_NAME.exe"
    fi
    
    echo "Building for $OS/$ARCH..."
    CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -a -installsuffix cgo -o $OUTPUT_DIR/$OUTPUT_NAME main.go
done

echo "✅ Build complete! Binaries available in $OUTPUT_DIR/"
ls -la $OUTPUT_DIR/
