.PHONY: help build local-login local-preview local-up staging-login staging-preview staging-up prod-login prod-preflight prod-preview prod-up

# Default target
help: ## Show this help message
	@echo "Available targets:"
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "  %-20s %s\n", $$1, $$2}'

# Build the Go binary
build: ## Build the Pulumi Go program
	go build

# Local stack commands
local-login: ## Login to local Pulumi backend
	pulumi login --local
	PULUMI_CONFIG_PASSPHRASE="" pulumi stack select local --create

local-preview: build local-login ## Preview local infrastructure changes
	PULUMI_CONFIG_PASSPHRASE="" pulumi preview --stack local

local-up: build local-login ## Deploy local infrastructure
	PULUMI_CONFIG_PASSPHRASE="" pulumi up --yes --stack local

local-destroy: local-login ## Destroy local infrastructure
	pulumi stack rm local --force --yes --preserve-config
	echo "Make sure to also delete your k8s cluster, e.g. minikube delete"

# Staging stack commands
staging-login: ## Login to staging Pulumi backend
	pulumi login gs://mcp-registry-staging-pulumi-state

staging-preview: build staging-login ## Preview staging infrastructure changes
	python3 scripts/deploy_stack.py staging preview

staging-up: build staging-login ## Deploy staging infrastructure
	python3 scripts/deploy_stack.py staging apply

# Production stack commands
prod-login: ## Login to production Pulumi backend
	pulumi login gs://mcp-registry-prod-pulumi-state

prod-preflight: build prod-login
	PULUMI_CONFIG_PASSPHRASE_FILE="$${PULUMI_CONFIG_PASSPHRASE_FILE:-$$PWD/passphrase.prod.txt}" python3 scripts/check_production_scaling.py

prod-preview: prod-preflight ## Preview production infrastructure changes
	python3 scripts/deploy_stack.py prod preview

prod-up: prod-preflight ## Deploy production infrastructure
	python3 scripts/deploy_stack.py prod apply
