name: PR Checks

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

jobs:
  # EN: Node.js frontend/packages checks
  # VI: Kiem tra frontend/packages Node.js
  node-check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup PNPM
        uses: pnpm/action-setup@v2
        with:
          version: 8

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

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Build shared packages
        run: pnpm --filter './packages/*' build

      - name: Lint all
        run: pnpm lint

      - name: Type check all
        run: pnpm typecheck

      - name: Build all
        run: pnpm build

  # EN: .NET microservices build check (matrix across all services)
  # VI: Kiem tra build .NET microservices (matrix qua tat ca services)
  dotnet-check:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        service:
          - name: iam-service-net
            project: IamService.API/IamService.API.csproj
          - name: merchant-service-net
            project: MerchantService.API/MerchantService.API.csproj
          - name: order-service-net
            project: OrderService.API/OrderService.API.csproj
          - name: catalog-service-net
            project: CatalogService.API/CatalogService.API.csproj
          - name: inventory-service-net
            project: InventoryService.API/InventoryService.API.csproj
          - name: wallet-service-net
            project: WalletService.API/WalletService.API.csproj
          - name: fnb-engine-net
            project: FnbEngine.API/FnbEngine.API.csproj
          - name: booking-service-net
            project: BookingService.API/BookingService.API.csproj
          - name: membership-service-net
            project: MembershipService.API/MembershipService.API.csproj
          - name: chat-service-net
            project: ChatService.API/ChatService.API.csproj
          - name: social-service-net
            project: SocialService.API/SocialService.API.csproj
          - name: storage-service-net
            project: StorageService.API/StorageService.API.csproj
          - name: mining-service-net
            project: MiningService.API/MiningService.API.csproj
          - name: mission-service-net
            project: MissionService.API/MissionService.API.csproj
          - name: promotion-service-net
            project: PromotionService.API/PromotionService.API.csproj
          - name: ads-manager-service-net
            project: AdsManagerService.API/AdsManagerService.API.csproj
          - name: ads-serving-service-net
            project: AdsServingService.API/AdsServingService.API.csproj
          - name: ads-billing-service-net
            project: AdsBillingService.API/AdsBillingService.API.csproj
          - name: ads-tracking-service-net
            project: AdsTrackingService.API/AdsTrackingService.API.csproj
          - name: ads-analytics-service-net
            project: AdsAnalyticsService.API/AdsAnalyticsService.API.csproj
          - name: mkt-facebook-service-net
            project: MktFacebookService.API/MktFacebookService.API.csproj
          - name: mkt-whatsapp-service-net
            project: MktWhatsappService.API/MktWhatsappService.API.csproj
          - name: mkt-x-service-net
            project: MktXService.API/MktXService.API.csproj
          - name: mkt-zalo-service-net
            project: MktZaloService.API/MktZaloService.API.csproj

    steps:
      - uses: actions/checkout@v4

      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '10.0.x'

      - name: Restore ${{ matrix.service.name }}
        run: dotnet restore services/${{ matrix.service.name }}/src/${{ matrix.service.project }}

      - name: Build ${{ matrix.service.name }}
        run: dotnet build services/${{ matrix.service.name }}/src/${{ matrix.service.project }} --configuration Release --no-restore
