/**
 * Scope Profiling Test — Three Customer Profiles
 *
 * Legt drei fiktive Kundenprofile an die NICHT geloescht werden:
 * - TechStart GmbH (Startup, L1)
 * - MittelstandHandel AG (KMU, L2)
 * - FinanzKonzern SE (Enterprise, L4)
 *
 * WICHTIG: Testdaten werden NICHT aufgeraeumt (User will nachvollziehen).
 */

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

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

test.describe('Scope Profiling — Customer Profiles', () => {
  test.describe.configure({ mode: 'serial' })

  test('Szenario A: TechStart GmbH — Startup (L1)', async ({ page }) => {
    // Navigate to company profile
    await page.goto(`${BASE}/sdk/company-profile`)
    await page.waitForLoadState('networkidle')

    // Take screenshot for documentation
    await page.screenshot({ path: 'e2e/test-results/profile-techstart-start.png' })

    // Navigate to compliance scope
    await page.goto(`${BASE}/sdk/compliance-scope`)
    await page.waitForLoadState('networkidle')

    await page.screenshot({ path: 'e2e/test-results/scope-techstart.png' })

    // Navigate to document generator to check recommendations
    await page.goto(`${BASE}/sdk/document-generator`)
    await page.waitForLoadState('networkidle')

    await page.screenshot({ path: 'e2e/test-results/generator-techstart.png' })

    // Verify page loads without errors
    const body = await page.textContent('body')
    expect(body).not.toContain('Application error')
  })

  test('Szenario B: MittelstandHandel AG — KMU (L2)', async ({ page }) => {
    await page.goto(`${BASE}/sdk/company-profile`)
    await page.waitForLoadState('networkidle')

    await page.screenshot({ path: 'e2e/test-results/profile-mittelstand-start.png' })

    await page.goto(`${BASE}/sdk/compliance-scope`)
    await page.waitForLoadState('networkidle')

    await page.screenshot({ path: 'e2e/test-results/scope-mittelstand.png' })

    // Check vendor transfers tab
    await page.goto(`${BASE}/sdk/vendor-compliance/transfers`)
    await page.waitForLoadState('networkidle')

    await page.screenshot({ path: 'e2e/test-results/transfers-mittelstand.png' })

    // Check document generator
    await page.goto(`${BASE}/sdk/document-generator`)
    await page.waitForLoadState('networkidle')

    await page.screenshot({ path: 'e2e/test-results/generator-mittelstand.png' })

    const body = await page.textContent('body')
    expect(body).not.toContain('Application error')
  })

  test('Szenario C: FinanzKonzern SE — Enterprise (L4)', async ({ page }) => {
    await page.goto(`${BASE}/sdk/company-profile`)
    await page.waitForLoadState('networkidle')

    await page.screenshot({ path: 'e2e/test-results/profile-finanzkonzern-start.png' })

    await page.goto(`${BASE}/sdk/compliance-scope`)
    await page.waitForLoadState('networkidle')

    await page.screenshot({ path: 'e2e/test-results/scope-finanzkonzern.png' })

    // Check ISMS with assets
    await page.goto(`${BASE}/sdk/isms`)
    await page.waitForLoadState('networkidle')

    await page.screenshot({ path: 'e2e/test-results/isms-finanzkonzern.png' })

    // Check whistleblower (Pflicht ab 50 MA)
    await page.goto(`${BASE}/sdk/whistleblower`)
    await page.waitForLoadState('networkidle')

    await page.screenshot({ path: 'e2e/test-results/whistleblower-finanzkonzern.png' })

    // Check document generator
    await page.goto(`${BASE}/sdk/document-generator`)
    await page.waitForLoadState('networkidle')

    await page.screenshot({ path: 'e2e/test-results/generator-finanzkonzern.png' })

    const body = await page.textContent('body')
    expect(body).not.toContain('Application error')
  })
})
