/**
 * SDK Module Reachability Test
 *
 * Prueft dass alle SDK-Module erreichbar sind (kein 404, kein Crash).
 * Schnellster Test — findet kaputte Seiten sofort.
 */

import { test, expect } from '@playwright/test'

const BASE = process.env.PLAYWRIGHT_BASE_URL || 'https://macmini:3007'

// All SDK module routes to test
const SDK_ROUTES = [
  // Phase 1: Vorbereitung
  '/sdk/company-profile',
  '/sdk/compliance-scope',
  '/sdk/advisory-board',
  '/sdk/screening',
  '/sdk/source-policy',

  // Phase 2: Analyse
  '/sdk/requirements',
  '/sdk/controls',
  '/sdk/evidence',
  '/sdk/risks',
  '/sdk/ai-act',
  '/sdk/audit-checklist',
  '/sdk/audit-report',

  // Phase 3: Dokumentation
  '/sdk/obligations',
  '/sdk/dsfa',
  '/sdk/tom',
  '/sdk/loeschfristen',
  '/sdk/vvt',

  // Phase 4: Rechtliche Texte
  '/sdk/einwilligungen',
  '/sdk/consent',
  '/sdk/cookie-banner',
  '/sdk/document-generator',
  '/sdk/workflow',

  // Phase 5: Betrieb
  '/sdk/dsr',
  '/sdk/escalations',
  '/sdk/vendor-compliance',
  '/sdk/vendor-compliance/transfers',
  '/sdk/consent-management',
  '/sdk/email-templates',
  '/sdk/notfallplan',
  '/sdk/incidents',
  '/sdk/whistleblower',
  '/sdk/academy',
  '/sdk/training',
  '/sdk/control-library',

  // Zusatzmodule
  '/sdk/isms',
  '/sdk/iace',
  '/sdk/agent',
  '/sdk/rag',
  '/sdk/quality',
  '/sdk/security-backlog',
  '/sdk/reporting',
  '/sdk/tom-generator',
]

test.describe('SDK Module Reachability', () => {
  for (const route of SDK_ROUTES) {
    test(`${route} is reachable`, async ({ page }) => {
      const response = await page.goto(`${BASE}${route}`, {
        waitUntil: 'domcontentloaded',
        timeout: 15000,
      })

      // Page should load successfully (not 404 or 500)
      expect(response?.status()).toBeLessThan(400)

      // Wait for client-side hydration
      await page.waitForTimeout(2000)

      // Check no visible 404 page or application error (not RSC payload)
      const has404Page = await page.locator('h1').filter({ hasText: '404' }).count()
      const hasAppError = await page.getByText('Application error').count()
      expect(has404Page).toBe(0)
      expect(hasAppError).toBe(0)
    })
  }
})
