# --- A2UI Starter Makefile ---

# Project Variables
PROJECT_ID ?= $(shell gcloud config get-value project)
REGION ?= us-central1
SERVICE_NAME = agent-ops-backend
IMAGE_TAG = us-central1-docker.pkg.dev/$(PROJECT_ID)/agent-repo/$(SERVICE_NAME):latest

.PHONY: help dev build deploy-cloud-run deploy-firebase deploy-gke audit deploy-prod scan-secrets ui-audit audit-all

help:
	@echo "Available commands:"
	@echo "  make dev               - Start local development server"
	@echo "  make build             - Build production assets"
	@echo "  make audit-all         - Run ALL audits and generate Final Report"
	@echo "  make reliability       - Run unit tests and regression suite"
	@echo "  make scan-secrets      - Scan for hardcoded API keys & credentials"
	@echo "  make ui-audit          - Run Face Auditor (UI/UX best practices)"
	@echo "  make audit             - Run Agent Optimizer audit"
	@echo "  make arch-review       - Run Google Well-Architected design review"
	@echo "  make quality-baseline  - Start iterative Quality Hill Climbing"
	@echo "  make red-team          - Run adversarial security audit"
	@echo "  make load-test         - Run base load test"
	@echo "  make deploy-prod       - Deploy to production (All Audits -> Cloud Run + Firebase)"
	@echo "  make deploy-cloud-run  - Deploy to Google Cloud Run"
	@echo "  make deploy-firebase   - Deploy to Firebase Hosting"



dev:
	npm run dev

build:
	npm run build

# 🏁 Master Audit: Run all modules and generate report
audit-all:
	@python3 src/backend/ops/orchestrator.py

# 🛡️ Reliability: Unit tests and regression suite
reliability:
	@python3 src/backend/ops/reliability.py

# 🔍 The Optimizer: Audit your agent for waste
audit:
	@python3 src/backend/optimizer.py src/backend/agent.py

# 🏛️ Architecture: Design review against Google Well-Architected Framework
arch-review:
	@python3 src/backend/ops/arch_review.py

# 🧗 Quality: Iterative Hill Climbing optimization
quality-baseline:
	@python3 src/backend/eval/quality_climber.py climb

# 🧪 Secrets: Scan for hardcoded credentials
scan-secrets:
	@python3 src/backend/ops/secret_scanner.py .

# 🎨 UI/UX: Face Auditor for frontend quality
ui-audit:
	@python3 src/backend/ops/ui_auditor.py src

# 🔥 Red Team: Unleash self-hacking security audit

red-team:
	@python3 src/backend/eval/red_team.py src/backend/agent.py

# ⚡ Load Test: Stress test your agent endpoint (Usage: make load_test REQUESTS=100 CONCURRENCY=10)
REQUESTS ?= 50

CONCURRENCY ?= 5
URL ?= http://localhost:8000/agent/query?q=healthcheck

load_test:
	@python3 src/backend/eval/load_test.py run --url $(URL) --requests $(REQUESTS) --concurrency $(CONCURRENCY)

# 🚀 Production: The Vercel-style 1-click deploy
deploy-prod: audit-all build

	@echo "📦 Containerizing and deploying to Cloud Run..."
	gcloud run deploy $(SERVICE_NAME) --source . --region $(REGION) --allow-unauthenticated --port 80
	@echo "🔥 Deploying frontend to Firebase..."
	firebase deploy --only hosting

# 🚀 Cloud Run: The fastest way to production
deploy-cloud-run:
	gcloud run deploy $(SERVICE_NAME) --source . --region $(REGION) --allow-unauthenticated --port 80

# 🔥 Firebase: Optimized for frontend hosting
deploy-firebase: build
	firebase deploy --only hosting

# ☸️ GKE: Enterprise container orchestration
deploy-gke:
	docker build -t $(IMAGE_TAG) .
	docker push $(IMAGE_TAG)
	@echo "Updating deployment.yaml..."
	sed -i '' 's|image: .*|image: $(IMAGE_TAG)|' deployment.yaml || true
	kubectl apply -f deployment.yaml || echo "No deployment.yaml found. Please create one based on DEPLOYMENT.md"
