#!/bin/bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

if [ -f "$PROJECT_ROOT/.env" ]; then
    set -a
    source "$PROJECT_ROOT/.env"
    set +a
fi

REGISTRY="${REGISTRY:?REGISTRY is required}"
IMAGE_TAG="${IMAGE_TAG:?IMAGE_TAG is required}"

usage() {
    echo "Usage: $0 [--help]"
    echo "Pull Docker images for Azaion.Detections from the registry."
    exit 0
}

for arg in "$@"; do
    case "$arg" in
        --help) usage ;;
    esac
done

IMAGE="${REGISTRY}/azaion/detections-cpu:${IMAGE_TAG}"

echo "Pulling $IMAGE ..."
docker pull "$IMAGE"

echo "Verifying image digest..."
docker inspect --format='{{index .RepoDigests 0}}' "$IMAGE" 2>/dev/null || echo "Warning: digest not available for local images"

echo "Pull complete."
