#!/bin/bash
# Build Indeehub image from the Indeehub Prototype project
# Usage: ./build-from-prototype.sh [path-to-prototype]

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DEFAULT_PROTOTYPE="$SCRIPT_DIR/../../Indeedhub Prototype"
PROTOTYPE_DIR="${1:-$DEFAULT_PROTOTYPE}"
IMAGE_TAG="localhost/indeedhub:latest"

if [ ! -d "$PROTOTYPE_DIR" ]; then
    echo "❌ Indeehub Prototype not found at: $PROTOTYPE_DIR"
    echo "   Set path: $0 /path/to/Indeedhub\ Prototype"
    exit 1
fi

# Determine container runtime
RUNTIME="podman"
if ! command -v podman >/dev/null 2>&1; then
    RUNTIME="docker"
fi

echo "🔨 Building Indeehub from $PROTOTYPE_DIR"
cd "$PROTOTYPE_DIR"
$RUNTIME build -t "$IMAGE_TAG" .

echo "✅ Built $IMAGE_TAG"
echo ""
echo "You can now install Indeehub from the App Store in Archipelago."
