#!/usr/bin/env bash
set -Eeuo pipefail

log() { echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] $*"; }
fail() { echo "ERROR: $*" >&2; exit 1; }

export PROJECT_DIR="${PROJECT_DIR:-/app}"
SCRIPT_PATH="${PROJECT_DIR}/scripts/initialize_data.py"

[[ -f "$SCRIPT_PATH" ]] || fail "Seed/init script not found: $SCRIPT_PATH"

export FLASK_APP="${FLASK_APP:-${PROJECT_DIR}/scripts/run.py}"
export COMPONENT_NAME="${COMPONENT_NAME:-eveai_ops}"
export PYTHONPATH="${PYTHONPATH:-${PROJECT_DIR}:${PYTHONPATH-}}"

log "Running initialize_data.py (idempotent one-off per environment)..."
python "$SCRIPT_PATH"
log "initialize_data.py completed."