#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"

deploy_api() {
    fly secrets import --config apps/api/fly.toml --stage < .env.production
    fly deploy --config apps/api/fly.toml --dockerfile apps/api/Dockerfile
}

deploy_portal() {
    fly secrets import --config apps/portal/fly.toml --stage < .env.production
    fly deploy --config apps/portal/fly.toml --dockerfile apps/portal/Dockerfile
}

target="${1:-all}"

case "$target" in
    api)
        deploy_api
        ;;
    portal)
        deploy_portal
        ;;
    all)
        deploy_api
        deploy_portal
        ;;
    *)
        echo "Usage: $0 [api|portal]" >&2
        exit 1
        ;;
esac
