name: PR Checks

on:
  pull_request:
    branches: [main]
    types: [opened, synchronize, reopened]

jobs:
  lint:
    runs-on: ubuntu-latest

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

      - name: Setup Node.js
        uses: actions/setup-node@v6
        with:
          node-version: "24"
          cache: "npm"

      - name: Install dependencies
        run: npm ci --ignore-scripts

      - name: Run linting
        run: npm run lint
  check:
    runs-on: ubuntu-latest

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "24"
          cache: "npm"

      - name: Install dependencies
        run: npm ci --ignore-scripts

      - name: Run type checking
        run: npm run check
  tests:
    runs-on: ubuntu-latest

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "24"
          cache: "npm"

      - name: Install dependencies
        run: npm ci --ignore-scripts

      - name: Run unit tests
        run: npm run test:unit -- --run
        env:
          DATABASE_URL: "postgresql://test:test@localhost:5432/test"
          SMTP_HOST: "smtp.example.com"
          SMTP_PORT: "587"
          SMTP_SECURE: "false"
          SMTP_USER: "your-email@example.com"
          SMTP_PASS: "your-password"
          SMTP_FROM_NAME: "Open Reception"
          SMTP_FROM_EMAIL: "noreply@example.com"
          JWT_SECRET: "test"
          MANAGEMENT_DOMAIN: "example.com"

  build:
    runs-on: ubuntu-latest

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "24"
          cache: "npm"

      - name: Install dependencies
        run: npm ci --ignore-scripts

      - name: Build application
        run: npm run build
        env:
          DATABASE_URL: "postgresql://test:test@localhost:5432/test"
          SMTP_HOST: "smtp.example.com"
          SMTP_PORT: "587"
          SMTP_SECURE: "false"
          SMTP_USER: "your-email@example.com"
          SMTP_PASS: "your-password"
          SMTP_FROM_NAME: "Open Reception"
          SMTP_FROM_EMAIL: "noreply@example.com"
          JWT_SECRET: "test"
          MANAGEMENT_DOMAIN: "example.com"
