#!/usr/bin/env bash

set -euo pipefail

cd "$(dirname "$0")/../../" # Navigate to the root of the project

if [ -z "${STAGE:-}" ]; then
    echo "Error: STAGE environment variable is not set."
    exit 1
fi

if [ "${STAGE}" = "stg" ]; then
    read -p "You are deploying to "stg" environment. Are you sure? (y/N): " confirm
    if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
        echo "Deployment to STAGE environment cancelled."
        exit 1
    fi
fi

cd infra/stage
if [ $# -gt 0 ]; then
    npx cdk deploy "$@" --require-approval never --context stage="${STAGE}"
else
    npx cdk deploy --all --require-approval never --context stage="${STAGE}"
fi
