# One command per pipeline step. Run `make help` to list them.
PY ?= python
CONFIG ?= configs/config.yaml

.PHONY: help install data synthetic validate prepare eda train evaluate report serve test lint typecheck check all clean docker

help:          ## List the available commands
	@grep -E '^[a-z-]+:.*## ' Makefile | sed 's/:.*## /\t/'

install:       ## Install pinned dependencies and the package in editable mode
	$(PY) -m pip install -r requirements-dev.txt && $(PY) -m pip install -e . --no-deps && pre-commit install

data:          ## Download the real dataset from Kaggle (needs a Kaggle API token)
	$(PY) -m noshow.cli download --config $(CONFIG)

synthetic:     ## Create a full-size synthetic dataset with the same schema (no account needed)
	$(PY) scripts/make_synthetic.py --rows 110527 --out data/raw/noshowappointments-kagglev2-may-2016.csv

validate:      ## Check the raw data against the schema
	$(PY) -m noshow.cli validate --config $(CONFIG)

prepare:       ## Clean the data and build point-in-time features
	$(PY) -m noshow.cli prepare --config $(CONFIG)

eda:           ## Write the exploratory data analysis report and figures
	$(PY) -m noshow.cli eda --config $(CONFIG)

train:         ## Tune and train the candidate models, select the best, calibrate it
	$(PY) -m noshow.cli train --config $(CONFIG)

evaluate:      ## Final test-set evaluation, fairness, explanations and model card
	$(PY) -m noshow.cli evaluate --config $(CONFIG)

all: validate prepare eda train evaluate   ## Run the whole pipeline

serve:         ## Run the prediction API locally
	$(PY) -m flask --app noshow.serving.app run --debug --port 8000

test:          ## Run the test suite
	$(PY) -m pytest

lint:          ## Lint and check formatting
	ruff check . && ruff format --check .

typecheck:     ## Static type checks
	mypy

check: lint typecheck test   ## Everything CI runs

docker:        ## Build the serving image
	docker build -t noshow-api .

clean:         ## Remove generated data, models and reports
	rm -rf data/interim/* data/processed/* models/* reports/* runs/*
