name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  # ── API: build + test ──────────────────────────────────────────────────────
  api:
    name: API (dotnet build + test)
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:16-alpine
        env:
          POSTGRES_DB: meezi_test
          POSTGRES_USER: meezi
          POSTGRES_PASSWORD: meezi_test_pass
        ports: ["5432:5432"]
        options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10
      redis:
        image: redis:7-alpine
        ports: ["6379:6379"]
        options: --health-cmd "redis-cli ping" --health-interval 5s --health-timeout 3s --health-retries 10
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-dotnet@v4
        with:
          dotnet-version: "10.0.x"
      - name: Restore
        run: dotnet restore
      - name: Build
        run: dotnet build --no-restore -c Release
      - name: Test
        run: dotnet test --no-build -c Release --logger "console;verbosity=minimal"
        env:
          ConnectionStrings__DefaultConnection: Host=localhost;Port=5432;Database=meezi_test;Username=meezi;Password=meezi_test_pass
          ConnectionStrings__Redis: localhost:6379

  # ── Dashboard: typecheck ───────────────────────────────────────────────────
  dashboard:
    name: Dashboard (Next.js typecheck)
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: web/dashboard
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: "20"
          cache: npm
          cache-dependency-path: web/dashboard/package-lock.json
      - run: npm install --legacy-peer-deps --ignore-scripts
      - run: npx tsc --noEmit
        env:
          NEXT_PUBLIC_API_URL: http://localhost:5080

  # ── Finder: typecheck ──────────────────────────────────────────────────────
  finder:
    name: Finder (Next.js typecheck)
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: web/finder
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: "20"
          cache: npm
          cache-dependency-path: web/finder/package-lock.json
      - run: npm install --legacy-peer-deps --ignore-scripts
      - run: npx tsc --noEmit
        env:
          NEXT_PUBLIC_API_URL: http://localhost:5080
