# ============================================================
# INSIGHT MVP - CI Pipeline (Lint, Type-Check, Test, Build)
# ============================================================
# Wird bei jedem Push und Pull Request ausgefuehrt.
# ============================================================

name: CI

on:
  push:
    branches: [main, develop, 'feature/**', 'fix/**', 'hotfix/**']
  pull_request:
    branches: [main, develop]

jobs:
  # --------------------------------------------------------
  # Core-Service: Lint, Type-Check, Test, Build
  # --------------------------------------------------------
  core-service:
    name: Core-Service CI
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: packages/core-service

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

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

      - name: Install dependencies
        run: npm ci

      - name: Generate Prisma Client
        run: npx prisma generate --schema=prisma/core.schema.prisma

      - name: Lint
        run: npm run lint:check

      - name: Type-Check
        run: npm run typecheck

      - name: Test
        run: npm test -- --passWithNoTests

      - name: Build
        run: npm run build

  # --------------------------------------------------------
  # Frontend: Lint, Type-Check, Build
  # --------------------------------------------------------
  frontend:
    name: Frontend CI
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: packages/frontend

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

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

      - name: Install dependencies
        run: npm ci

      - name: Lint
        run: npm run lint:check

      - name: Type-Check
        run: npm run typecheck

      - name: Build
        run: npm run build
