# Targets assume a POSIX shell and .venv/bin/python. Windows users run the
# `python -m ...` lines directly from an activated .venv.
# Pass the country on the command line: make live COUNTRY=KEN
# COUNTRY defaults to the value in .env when omitted (the modules read it).
PY=.venv/bin/python
PIP=.venv/bin/pip
CARG=$(if $(COUNTRY),--country $(COUNTRY),)

.PHONY: setup setup-vps test lint check onboard live serve backfill status rundate nginx cron backup check-daily

setup:
	python3 -m venv .venv
	$(PIP) install -r requirements.txt
	@test -f .env || cp .env.example .env
	@echo "Edit .env, then run: make check COUNTRY=<ISO3>"

setup-vps:
	python3 -m venv .venv
	$(PIP) install -r requirements-vps.txt
	@test -f .env || cp .env.example .env

test:
	$(PY) -m pytest -q

lint:
	$(PY) -m ruff check .

check:
	$(PY) -m scripts.check_setup $(CARG)

onboard:
	$(PY) -m scripts.onboard_country $(CARG)

live:
	$(PY) -m app.daily_job $(CARG)

serve:
	$(PY) -m scripts.serve $(CARG)

backfill:
	$(PY) -m scripts.backfill $(CARG) --days 365

status:
	$(PY) -m scripts.db_status $(CARG)

# make rundate COUNTRY=KEN DATE=2026-10-20
rundate:
	$(PY) -m scripts.run_date $(CARG) $(DATE)

# Deployment helpers (docs/08_DEPLOYMENT.md). nginx and cron only validate and print;
# on the server add --out to write the files, or just run bash deploy/redeploy.sh.
nginx:
	$(PY) -m deploy.generate_nginx --check

cron:
	$(PY) -m deploy.generate_cron --check

# make backup COUNTRY=KEN
backup:
	$(PY) -m scripts.backup_db $(CARG)

# make check-daily COUNTRY=KEN   (add ARGS=--test to force an email)
check-daily:
	$(PY) -m scripts.check_daily_run $(CARG) $(ARGS)
