set shell := ["powershell", "-NoProfile", "-Command"]

# Container runtime: uncomment the line for your preferred tool
# docker := "docker"
docker := "podman"

# KollectAI-ETL Task Runner
# Uses Commitizen (https://commitizen-tools.github.io/commitizen/) for
# Conventional Commits enforcement, automated versioning, and changelog generation.
# Configuration: .cz.json (SemVer, conventional_commits schema)
# Hook config: .pre-commit-config.yaml (commit-msg stage validation)

# Full bootstrap: install uv, just, commitizen, pre-commit, and configure git hooks.
# Run this once after cloning the repo. Safe to re-run (idempotent).
# Requires: PowerShell (pwsh). Installs uv and just if missing.
bootstrap:
    pwsh -ExecutionPolicy Bypass -File ./setup.ps1

# Install commitizen and pre-commit, then configure git hooks.
# Requires: uv, just already installed. Use `just bootstrap` if not.
setup:
    uv tool install commitizen; uv tool install pre-commit; pre-commit install

# Refresh pre-commit hook versions to latest.
# Run after pulling changes that update .pre-commit-config.yaml.
update:
    pre-commit autoupdate

# Generate or update CHANGELOG.md from conventional commit history.
# Reads commits since the last tag and groups by type (feat, fix, etc.).
changelog:
    cz changelog

# Bump the project version based on commit history since the last tag.
# Commitizen determines the SemVer increment automatically:
#   feat commits    → minor bump
#   fix commits     → patch bump
#   BREAKING CHANGE → major bump
# Also updates CHANGELOG.md (update_changelog_on_bump is enabled in .cz.json).
bump:
    cz bump

# Start infrastructure services (PostgreSQL, Ollama, MinIO)
infra:
    {{docker}} compose up -d postgres ollama minio

# Run backend in dev mode
backend:
    cd backend/etl; ./mvnw spring-boot:run "-Dspring-boot.run.profiles=dev"

# Run frontend dev server
frontend:
    cd frontend/svelte; pnpm install; pnpm dev

# Start infra + backend + frontend for local development
dev:
    just infra; just backend; just frontend

# Build all artifacts
build:
    cd backend/etl; ./mvnw package -DskipTests
    cd frontend/svelte; pnpm build

# Run all tests
test:
    cd backend/etl; ./mvnw test
    cd frontend/svelte; pnpm test

# Run linting
lint:
    cd backend/etl; ./mvnw checkstyle:check
    cd frontend/svelte; pnpm lint

# Start all services via Docker Compose
up:
    {{docker}} compose up -d --build

# Stop all services
down:
    {{docker}} compose down
