name: CI

on:
  push:
    branches: [main, develop, "feature/**"]
  pull_request:
    branches: [main, develop]

jobs:
  quality:
    runs-on: ubuntu-latest
    timeout-minutes: 20

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: "20"
          cache: npm

      - name: Install dependencies
        run: npm ci

      - name: Validate Prisma schema
        run: npm run db:validate

      - name: Lint (tsc)
        run: npm run lint

      - name: Unit tests
        run: npm run test:unit

      - name: Integration tests
        run: npm run test:integration
        env:
          JWT_SECRET: ci-test-jwt-secret-32chars-min!!
          HOST_SERVICE_TOKENS: '{"demo-host-token":{"customerId":"CUST_001","permissions":["pricing:markup:write"]}}'

      - name: Build
        run: npm run build
        env:
          JWT_SECRET: ci-test-jwt-secret-32chars-min!!
          HOST_SERVICE_TOKENS: '{"demo-host-token":{"customerId":"CUST_001","permissions":["pricing:markup:write"]}}'
