name: Lint

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

jobs:
  lint-api:
    name: Lint API (NestJS)
    runs-on: ubuntu-latest
    permissions:
      contents: read
    defaults:
      run:
        working-directory: ./api

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Cache node modules
        uses: actions/cache@v4
        with:
          path: ./api/node_modules
          key: ${{ runner.os }}-api-node-${{ hashFiles('api/package.json') }}
          restore-keys: |
            ${{ runner.os }}-api-node-

      - name: Install dependencies
        run: npm install --prefer-offline --no-audit

      - name: Run ESLint
        run: npm run lint:check

      - name: Run Prettier check
        run: npm run format:check

  lint-web:
    name: Lint Web (Next.js)
    runs-on: ubuntu-latest
    permissions:
      contents: read
    defaults:
      run:
        working-directory: ./web

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Cache node modules
        uses: actions/cache@v4
        with:
          path: ./web/node_modules
          key: ${{ runner.os }}-web-node-${{ hashFiles('web/package.json') }}
          restore-keys: |
            ${{ runner.os }}-web-node-

      - name: Install dependencies
        run: npm install --prefer-offline --no-audit

      - name: Run Next.js lint
        run: npm run lint

      - name: Run Prettier check
        run: npm run format:check
