#!/bin/bash

# Minimal build script for debian-bootc-image-builder
# This script builds a minimal version to test basic functionality

set -e

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

# Function to print colored output
print_status() {
    echo -e "${GREEN}[INFO]${NC} $1"
}

print_warning() {
    echo -e "${YELLOW}[WARNING]${NC} $1"
}

print_error() {
    echo -e "${RED}[ERROR]${NC} $1"
}

# Check if we're in the right directory
if [ ! -f "bib/go.mod" ]; then
    print_error "Please run this script from the project root directory"
    exit 1
fi

# Create bin directory if it doesn't exist
mkdir -p bin

print_status "Building minimal debian-bootc-image-builder..."

# Backup original go.mod
cp bib/go.mod bib/go.mod.backup

# Use minimal go.mod
cp bib/go.mod.minimal bib/go.mod

# Build the minimal binary
cd bib
go mod tidy
go build -o ../bin/debian-bootc-image-builder-minimal -tags minimal ./cmd/debian-bootc-image-builder

if [ $? -eq 0 ]; then
    print_status "Minimal build successful!"
    print_status "Binary created at: bin/debian-bootc-image-builder-minimal"
    
    # Show binary info
    if [ -f "../bin/debian-bootc-image-builder-minimal" ]; then
        print_status "Binary size: $(du -h ../bin/debian-bootc-image-builder-minimal | cut -f1)"
        print_status "Binary info:"
        file ../bin/debian-bootc-image-builder-minimal
    fi
else
    print_error "Minimal build failed!"
    # Restore original go.mod
    mv go.mod.backup go.mod
    exit 1
fi

# Restore original go.mod
mv go.mod.backup go.mod

cd ..

print_status "Minimal build completed successfully!"
print_warning "This is a minimal implementation for testing only."
print_status "To test: ./bin/debian-bootc-image-builder-minimal --help"

