#!/usr/bin/env bash
# OrderOp macro-service databases (PostgreSQL): migrate and seed helpers.
# Usage:
#   ./scripts/orderop-db.sh setup              # php artisan migrate + orderop:migrate-all
#   ./scripts/orderop-db.sh setup-fresh        # migrate:fresh + orderop:migrate-all --fresh
#   ./scripts/orderop-db.sh migrate-all
#   ./scripts/orderop-db.sh migrate-fresh-all  # orderop:migrate-all --fresh
#   ./scripts/orderop-db.sh seed-all
#   ./scripts/orderop-db.sh migrate orderop_identity [--fresh]
#   ./scripts/orderop-db.sh seed orderop_catalog
#   ./scripts/orderop-db.sh migrate-file identity/2026_03_31_201001_identity_create_users_table.php
set -euo pipefail
cd "$(dirname "$0")/.."
case "${1:-}" in
  setup)
    php artisan orderop:setup "${@:2}"
    ;;
  setup-fresh)
    php artisan orderop:setup --fresh --force "${@:2}"
    ;;
  migrate-all)
    php artisan orderop:migrate-all "${@:2}"
    ;;
  migrate-fresh-all)
    php artisan orderop:migrate-all --fresh --force "${@:2}"
    ;;
  seed-all)
    php artisan orderop:seed-all "${@:2}"
    ;;
  migrate)
    php artisan orderop:migrate "${@:2}"
    ;;
  seed)
    php artisan orderop:seed "${@:2}"
    ;;
  migrate-file)
    php artisan orderop:migrate-file "${@:2}"
    ;;
  *)
    echo "Usage: $0 {setup|setup-fresh|migrate-all|migrate-fresh-all|seed-all|migrate <connection>|seed <connection>|migrate-file <path-under-migrations>}" >&2
    echo "Connections: orderop_identity, orderop_catalog, orderop_transaction_service, orderop_fulfillment_service, orderop_engagement_service, orderop_analytics_service, orderop_integration" >&2
    exit 1
    ;;
esac
