.PHONY: help venv sync qa check archive build clean

UV ?= uv
VENV_DIR := .venv

help:
	@echo "Targets:"
	@echo "  make venv        - create .venv if missing"
	@echo "  make update_python_deps - create .venv if missing, then sync python deps"
	@echo "  make qa                 - run QA (may write fixes)"
	@echo "  make check              - run QA in check+diff mode (CI-friendly)"
	@echo "  make archive            - create wwwroot/sharekinks.zip"
	@echo "  make build              - qa then archive"
	@echo "  make deploy_api         - deploy the sharekinks-api Cloudflare worker"
	@echo "  make deploy_frontend    - deploy_api then deploy_frontend"
	@echo "  make deploy             - deploy the sharekinks Cloudflare worker"
	@echo "  make clean              - remove generated archive"

venv:
	@test -d $(VENV_DIR) || $(UV) venv && $(UV) pip install -r tools/requirements.txt

update_python_deps: venv
	$(UV) pip install -r tools/requirements.txt

qa:
	$(UV) run python tools/qa.py

check:
	$(UV) run python tools/qa.py --check --diff

archive:
	$(UV) run python tools/archive.py

build: qa archive
	@echo "Build completed successfully."

deploy_api:
	cd ./cf-worker && npx wrangler deploy

deploy_frontend: qa archive
	npx wrangler deploy

deploy: deploy_api deploy_frontend 

clean:
	rm -f wwwroot/sharekinks.zip
