version: '3'

includes:
  data:
    taskfile: ./Taskfile.data.yml
    flatten: true

vars:
  DATA_DIR: /bulk/property-data
  WIDE_OUTPUT: "{{.DATA_DIR}}/wide.parquet"
  POIS_FILTERED_OUTPUT: "{{.DATA_DIR}}/filtered_uk_pois.parquet"

tasks:
  install:
    desc: Install dependencies
    cmds:
      - uv sync
      - cd frontend && npm install

  test:
    cmds:
      - uv run -m pipeline.utils.test_fuzzy_join
      - uv run pytest pipeline/utils/test_haversine.py
      - uv run pytest pipeline/utils/test_poi_counts.py
  
  test:server:
    desc: Run Rust backend tests
    dir: server-rs
    cmds:
      - cargo test

  dev:server:
    desc: Run Rust backend on port 8001 (debug build, fast compile)
    dir: server-rs
    cmds:
      - cargo run -- --data {{.WIDE_OUTPUT}} --pois {{.POIS_FILTERED_OUTPUT}}

  dev:server:release:
    desc: Run Rust backend on port 8001 (release build)
    dir: server-rs
    cmds:
      - cargo run --release -- --data {{.WIDE_OUTPUT}} --pois {{.POIS_FILTERED_OUTPUT}}

  dev:og:
    desc: Run OG screenshot sidecar on port 8002
    dir: og-screenshot
    env:
      CACHE_DIR: /tmp/og-cache
      NARROWIT_URL: http://localhost:3030
    cmds:
      - npm install
      - npx playwright install --with-deps chromium
      - npm run build
      - npm start

  dev:frontend:
    desc: Run frontend dev server on port 3030 (proxies /api to :8001)
    dir: frontend
    deps:
      - install
    cmds:
      - npm run dev

  build:server:
    desc: Build server for production
    dir: server-rs
    cmds:
      - cargo build --release

  build:frontend:
    desc: Build frontend for production
    dir: frontend
    cmds:
      - npm run typecheck
      - npm run build

  lint:
    desc: Lint all code (Python, TypeScript, and Rust)
    cmds:
      - task: lint:python
      - task: lint:frontend
      - task: lint:rust

  lint:python:
    desc: Lint Python code with ruff and check for unused dependencies
    cmds:
      - uv run ruff check .
      - uv run deptry .

  lint:frontend:
    desc: Lint frontend TypeScript code
    dir: frontend
    cmds:
      - npm run lint
      - npm run format:check

  lint:rust:
    desc: Lint Rust code with clippy, check formatting, and detect unused dependencies
    dir: server-rs
    cmds:
      - cargo clippy -- -D warnings
      - cargo fmt --check
      - cargo machete

  format:
    desc: Format all code (Python, TypeScript, and Rust)
    cmds:
      - task: format:python
      - task: format:frontend
      - task: format:rust

  format:python:
    desc: Format Python code with ruff
    cmds:
      - uv run ruff check --fix .
      - uv run ruff format .

  format:frontend:
    desc: Format frontend TypeScript code
    dir: frontend
    cmds:
      - npm run lint:fix
      - npm run format

  format:rust:
    desc: Format Rust code with cargo fmt
    dir: server-rs
    cmds:
      - cargo fmt --all

  check:
    desc: Run all checks (lint, typecheck, build)
    cmds:
      - task: lint
      - task: build:server
      - task: build:frontend
      - task: test
      - task: test:server
