'use client'

import { DevPortalLayout, ApiEndpoint, CodeBlock, ParameterTable, InfoBox } from '@/components/DevPortalLayout'

export default function IACEApiPage() {
  return (
    <DevPortalLayout
      title="IACE API"
      description="Industrial AI Compliance Engine — CE-Risikobewertung, Gefahrenanalyse und Technische Dokumentation"
    >
      <h2>Uebersicht</h2>
      <p>
        Die IACE (Industrial AI Compliance Engine) API ermoeglicht die vollstaendige
        CE-Risikobewertung fuer Maschinen und Industrieprodukte. Sie deckt den gesamten
        Compliance-Lebenszyklus ab:
      </p>
      <ul>
        <li>Projektmanagement und Onboarding</li>
        <li>Komponentenverwaltung und Regulatorische Klassifizierung</li>
        <li>Gefahrenanalyse mit 102 Hazard-Patterns (ISO 12100)</li>
        <li>4-Faktor-Risikobewertung (S/E/P/A)</li>
        <li>3-Stufen-Massnahmenhierarchie (Design, Schutz, Information)</li>
        <li>Verifizierungsplaene und Evidenz-Management</li>
        <li>LLM-gestuetzte Technische Dokumentation (CE Technical File)</li>
        <li>Monitoring und Audit Trail</li>
      </ul>

      <InfoBox type="info" title="Basis-Pfad">
        Alle Endpoints verwenden den Basis-Pfad <code>/sdk/v1/iace</code>.
        Authentifizierung erfolgt ueber Bearer Token im Authorization-Header.
      </InfoBox>

      {/* ============================================================ */}
      {/* PROJECT MANAGEMENT                                           */}
      {/* ============================================================ */}

      <h2>Project Management</h2>
      <p>Erstellen und verwalten Sie IACE-Projekte fuer einzelne Maschinen oder Produkte.</p>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects" description="Neues IACE-Projekt erstellen" />

      <h3>Request Body</h3>
      <ParameterTable
        parameters={[
          { name: 'machine_name', type: 'string', required: true, description: 'Name der Maschine / des Produkts' },
          { name: 'machine_type', type: 'string', required: true, description: 'Maschinentyp (z.B. "CNC-Fraesmaschine", "Industrieroboter")' },
          { name: 'manufacturer', type: 'string', required: false, description: 'Hersteller-Name' },
          { name: 'description', type: 'string', required: false, description: 'Beschreibung des Produkts und seiner Einsatzzwecke' },
        ]}
      />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/projects" \\
  -H "Authorization: Bearer YOUR_API_KEY" \\
  -H "Content-Type: application/json" \\
  -d '{
    "machine_name": "RoboArm X500",
    "machine_type": "Industrieroboter",
    "manufacturer": "TechCorp GmbH",
    "description": "6-Achsen-Industrieroboter fuer Montagearbeiten"
  }'`}
      </CodeBlock>

      <h3>Response (201 Created)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "id": "proj_a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "machine_name": "RoboArm X500",
    "machine_type": "Industrieroboter",
    "manufacturer": "TechCorp GmbH",
    "description": "6-Achsen-Industrieroboter fuer Montagearbeiten",
    "status": "draft",
    "completeness_score": 0,
    "created_at": "2026-03-16T10:00:00Z"
  }
}`}
      </CodeBlock>

      <ApiEndpoint method="GET" path="/sdk/v1/iace/projects" description="Alle Projekte des Tenants auflisten" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X GET "https://api.breakpilot.io/sdk/v1/iace/projects" \\
  -H "Authorization: Bearer YOUR_API_KEY"`}
      </CodeBlock>

      <h3>Response (200 OK)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": [
    {
      "id": "proj_a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "machine_name": "RoboArm X500",
      "machine_type": "Industrieroboter",
      "status": "in_progress",
      "completeness_score": 72,
      "hazard_count": 14,
      "created_at": "2026-03-16T10:00:00Z"
    }
  ]
}`}
      </CodeBlock>

      <ApiEndpoint method="GET" path="/sdk/v1/iace/projects/:id" description="Projektdetails inkl. Komponenten und Klassifizierungen laden" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X GET "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4" \\
  -H "Authorization: Bearer YOUR_API_KEY"`}
      </CodeBlock>

      <ApiEndpoint method="PUT" path="/sdk/v1/iace/projects/:id" description="Projektfelder aktualisieren" />
      <ApiEndpoint method="DELETE" path="/sdk/v1/iace/projects/:id" description="Projekt archivieren (Soft Delete)" />

      {/* ============================================================ */}
      {/* ONBOARDING                                                   */}
      {/* ============================================================ */}

      <h2>Onboarding</h2>
      <p>Initialisierung aus Firmenprofil und Vollstaendigkeitspruefung.</p>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/init-from-profile" description="Projekt aus Company Profile und Compliance Scope initialisieren" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/init-from-profile" \\
  -H "Authorization: Bearer YOUR_API_KEY"`}
      </CodeBlock>

      <h3>Response (200 OK)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "initialized_fields": ["manufacturer", "description", "machine_type"],
    "suggested_regulations": ["machinery_regulation", "low_voltage", "emc"],
    "message": "Projekt aus Firmenprofil initialisiert. 3 Felder uebernommen."
  }
}`}
      </CodeBlock>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/completeness-check" description="Vollstaendigkeitspruefung (25 Gates) durchfuehren" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/completeness-check" \\
  -H "Authorization: Bearer YOUR_API_KEY"`}
      </CodeBlock>

      <h3>Response (200 OK)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "score": 72,
    "total_gates": 25,
    "passed_gates": 18,
    "gates": [
      { "id": "G01", "name": "Maschinenidentifikation", "status": "passed" },
      { "id": "G02", "name": "Komponentenliste", "status": "passed" },
      { "id": "G03", "name": "Regulatorische Klassifizierung", "status": "passed" },
      { "id": "G04", "name": "Gefahrenanalyse", "status": "warning", "message": "3 Gefahren ohne Massnahmen" },
      { "id": "G05", "name": "Risikobewertung", "status": "failed", "message": "5 Gefahren nicht bewertet" }
    ]
  }
}`}
      </CodeBlock>

      {/* ============================================================ */}
      {/* COMPONENTS                                                   */}
      {/* ============================================================ */}

      <h2>Components</h2>
      <p>Verwalten Sie die Komponenten einer Maschine oder eines Produkts.</p>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/components" description="Komponente hinzufuegen" />

      <h3>Request Body</h3>
      <ParameterTable
        parameters={[
          { name: 'name', type: 'string', required: true, description: 'Komponentenname' },
          { name: 'component_type', type: 'string', required: true, description: 'Typ (z.B. "actuator", "sensor", "controller", "structural")' },
          { name: 'is_safety_relevant', type: 'boolean', required: false, description: 'Sicherheitsrelevante Komponente (default: false)' },
        ]}
      />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/components" \\
  -H "Authorization: Bearer YOUR_API_KEY" \\
  -H "Content-Type: application/json" \\
  -d '{
    "name": "Servo-Antrieb Achse 1",
    "component_type": "actuator",
    "is_safety_relevant": true
  }'`}
      </CodeBlock>

      <h3>Response (201 Created)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "id": "comp_1234abcd",
    "name": "Servo-Antrieb Achse 1",
    "component_type": "actuator",
    "is_safety_relevant": true,
    "created_at": "2026-03-16T10:05:00Z"
  }
}`}
      </CodeBlock>

      <ApiEndpoint method="GET" path="/sdk/v1/iace/projects/:id/components" description="Alle Komponenten des Projekts auflisten" />
      <ApiEndpoint method="PUT" path="/sdk/v1/iace/projects/:id/components/:cid" description="Komponente aktualisieren" />
      <ApiEndpoint method="DELETE" path="/sdk/v1/iace/projects/:id/components/:cid" description="Komponente loeschen" />

      {/* ============================================================ */}
      {/* REGULATORY CLASSIFICATION                                    */}
      {/* ============================================================ */}

      <h2>Regulatory Classification</h2>
      <p>Automatische Klassifizierung nach anwendbaren Regulierungen (Maschinenverordnung, Niederspannung, EMV, etc.).</p>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/classify" description="Alle anwendbaren Regulierungen klassifizieren" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/classify" \\
  -H "Authorization: Bearer YOUR_API_KEY"`}
      </CodeBlock>

      <h3>Response (200 OK)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "classifications": [
      {
        "regulation": "machinery_regulation",
        "title": "Maschinenverordnung (EU) 2023/1230",
        "applicable": true,
        "confidence": 0.95,
        "reason": "Industrieroboter faellt unter Annex I der Maschinenverordnung"
      },
      {
        "regulation": "low_voltage",
        "title": "Niederspannungsrichtlinie 2014/35/EU",
        "applicable": true,
        "confidence": 0.88,
        "reason": "Betriebsspannung 400V AC"
      },
      {
        "regulation": "ai_act",
        "title": "AI Act (EU) 2024/1689",
        "applicable": false,
        "confidence": 0.72,
        "reason": "Keine KI-Komponente identifiziert"
      }
    ]
  }
}`}
      </CodeBlock>

      <ApiEndpoint method="GET" path="/sdk/v1/iace/projects/:id/classifications" description="Klassifizierungsergebnisse abrufen" />
      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/classify/:regulation" description="Einzelne Regulierung klassifizieren" />

      {/* ============================================================ */}
      {/* HAZARDS & PATTERN MATCHING                                   */}
      {/* ============================================================ */}

      <h2>Hazards &amp; Pattern Matching</h2>
      <p>
        Gefahrenanalyse nach ISO 12100 mit 102 Hazard-Patterns. Die Pattern-Matching-Engine
        erkennt automatisch Gefahren basierend auf Maschinentyp, Komponenten und Energiequellen.
      </p>

      <InfoBox type="info" title="102 Hazard-Patterns">
        Die Engine enthaelt 102 vordefinierte Gefahrenmuster (HP001-HP102), die nach
        ISO 12100 Anhang A kategorisiert sind: mechanisch, elektrisch, thermisch, Laerm,
        Vibration, Strahlung, Materialien/Substanzen und ergonomisch.
      </InfoBox>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/hazards" description="Neue Gefahr erstellen" />
      <ApiEndpoint method="GET" path="/sdk/v1/iace/projects/:id/hazards" description="Alle Gefahren des Projekts auflisten" />
      <ApiEndpoint method="PUT" path="/sdk/v1/iace/projects/:id/hazards/:hid" description="Gefahr aktualisieren" />

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/hazards/suggest" description="KI-gestuetzte Gefahrenvorschlaege generieren" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/hazards/suggest" \\
  -H "Authorization: Bearer YOUR_API_KEY"`}
      </CodeBlock>

      <h3>Response (200 OK)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "suggestions": [
      {
        "hazard_type": "mechanical",
        "title": "Quetschgefahr durch bewegliche Roboterarme",
        "description": "Unkontrollierte Bewegung der Achsen kann zu Quetschungen fuehren",
        "iso_reference": "ISO 12100 Anhang A.1",
        "severity": "high",
        "confidence": 0.91
      },
      {
        "hazard_type": "electrical",
        "title": "Stromschlaggefahr bei Wartungsarbeiten",
        "description": "Zugang zu spannungsfuehrenden Teilen bei geoeffnetem Schaltschrank",
        "iso_reference": "ISO 12100 Anhang A.2",
        "severity": "critical",
        "confidence": 0.87
      }
    ]
  }
}`}
      </CodeBlock>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/match-patterns" description="Pattern-Matching-Engine ausfuehren (102 Patterns)" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/match-patterns" \\
  -H "Authorization: Bearer YOUR_API_KEY"`}
      </CodeBlock>

      <h3>Response (200 OK)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "total_patterns_checked": 102,
    "matches": 14,
    "results": [
      {
        "pattern_id": "HP003",
        "title": "Crushing hazard from linear actuator",
        "category": "mechanical",
        "match_score": 0.94,
        "matched_components": ["Servo-Antrieb Achse 1", "Linearfuehrung"],
        "matched_energy_sources": ["EN03"],
        "suggested_hazard": {
          "title": "Quetschgefahr durch Linearantrieb",
          "severity": "high"
        }
      }
    ]
  }
}`}
      </CodeBlock>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/apply-patterns" description="Pattern-Matching-Ergebnisse als Gefahren uebernehmen" />
      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/hazards/:hid/suggest-measures" description="Massnahmenvorschlaege fuer eine Gefahr generieren" />
      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/mitigations/:mid/suggest-evidence" description="Evidenz-Vorschlaege fuer eine Massnahme generieren" />

      {/* ============================================================ */}
      {/* RISK ASSESSMENT                                              */}
      {/* ============================================================ */}

      <h2>Risk Assessment</h2>
      <p>
        4-Faktor-Risikobewertung nach ISO 12100 mit den Parametern Schwere (S),
        Exposition (E), Eintrittswahrscheinlichkeit (P) und Vermeidbarkeit (A).
      </p>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/hazards/:hid/assess" description="Risiko bewerten (S/E/P/A, Inherent Risk, C_eff, Residual Risk)" />

      <h3>Request Body</h3>
      <ParameterTable
        parameters={[
          { name: 'severity', type: 'number (1-4)', required: true, description: 'Schwere: 1=gering, 2=mittel, 3=schwer, 4=toedlich' },
          { name: 'exposure', type: 'number (1-4)', required: true, description: 'Exposition: 1=selten, 2=gelegentlich, 3=haeufig, 4=dauernd' },
          { name: 'probability', type: 'number (1-4)', required: true, description: 'Eintrittswahrscheinlichkeit: 1=unwahrscheinlich, 2=moeglich, 3=wahrscheinlich, 4=sehr wahrscheinlich' },
          { name: 'avoidance', type: 'number (1-4)', required: true, description: 'Vermeidbarkeit: 1=leicht, 2=moeglich, 3=schwer, 4=unmoeglich' },
        ]}
      />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/hazards/haz_5678/assess" \\
  -H "Authorization: Bearer YOUR_API_KEY" \\
  -H "Content-Type: application/json" \\
  -d '{
    "severity": 4,
    "exposure": 3,
    "probability": 2,
    "avoidance": 3
  }'`}
      </CodeBlock>

      <h3>Response (200 OK)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "hazard_id": "haz_5678",
    "severity": 4,
    "exposure": 3,
    "probability": 2,
    "avoidance": 3,
    "inherent_risk": 12,
    "risk_level": "high",
    "c_eff": 0.65,
    "residual_risk": 4.2,
    "residual_risk_level": "medium",
    "risk_acceptable": false,
    "recommendation": "Zusaetzliche Schutzmassnahmen erforderlich. 3-Stufen-Hierarchie anwenden."
  }
}`}
      </CodeBlock>

      <ApiEndpoint method="GET" path="/sdk/v1/iace/projects/:id/risk-summary" description="Aggregierte Risikouebersicht des Projekts" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X GET "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/risk-summary" \\
  -H "Authorization: Bearer YOUR_API_KEY"`}
      </CodeBlock>

      <h3>Response (200 OK)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "total_hazards": 14,
    "assessed": 12,
    "unassessed": 2,
    "risk_distribution": {
      "critical": 1,
      "high": 4,
      "medium": 5,
      "low": 2
    },
    "residual_risk_distribution": {
      "critical": 0,
      "high": 1,
      "medium": 3,
      "low": 8
    },
    "average_c_eff": 0.71,
    "overall_risk_acceptable": false
  }
}`}
      </CodeBlock>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/hazards/:hid/reassess" description="Risiko nach Massnahmen-Umsetzung neu bewerten" />

      {/* ============================================================ */}
      {/* MITIGATIONS                                                  */}
      {/* ============================================================ */}

      <h2>Mitigations</h2>
      <p>
        Massnahmenverwaltung nach der 3-Stufen-Hierarchie gemaess ISO 12100:
      </p>
      <ol>
        <li><strong>Design</strong> — Inherent Safe Design (Gefahrenbeseitigung durch Konstruktion)</li>
        <li><strong>Protective</strong> — Schutzeinrichtungen und technische Schutzmassnahmen</li>
        <li><strong>Information</strong> — Benutzerinformation (Warnhinweise, Anleitungen, Schulungen)</li>
      </ol>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/hazards/:hid/mitigations" description="Massnahme erstellen (3-Stufen-Hierarchie: design, protective, information)" />

      <h3>Request Body</h3>
      <ParameterTable
        parameters={[
          { name: 'title', type: 'string', required: true, description: 'Titel der Massnahme' },
          { name: 'description', type: 'string', required: true, description: 'Beschreibung der Massnahme' },
          { name: 'hierarchy_level', type: 'string', required: true, description: '"design" | "protective" | "information"' },
          { name: 'responsible', type: 'string', required: false, description: 'Verantwortliche Person oder Rolle' },
          { name: 'deadline', type: 'string (ISO 8601)', required: false, description: 'Umsetzungsfrist' },
        ]}
      />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/hazards/haz_5678/mitigations" \\
  -H "Authorization: Bearer YOUR_API_KEY" \\
  -H "Content-Type: application/json" \\
  -d '{
    "title": "Schutzgitter mit Sicherheitsschalter",
    "description": "Installation eines trennenden Schutzgitters mit Verriegelung nach ISO 14120",
    "hierarchy_level": "protective",
    "responsible": "Sicherheitsingenieur",
    "deadline": "2026-04-30T00:00:00Z"
  }'`}
      </CodeBlock>

      <h3>Response (201 Created)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "id": "mit_abcd1234",
    "hazard_id": "haz_5678",
    "title": "Schutzgitter mit Sicherheitsschalter",
    "hierarchy_level": "protective",
    "status": "planned",
    "verified": false,
    "created_at": "2026-03-16T11:00:00Z"
  }
}`}
      </CodeBlock>

      <ApiEndpoint method="PUT" path="/sdk/v1/iace/mitigations/:mid" description="Massnahme aktualisieren" />
      <ApiEndpoint method="POST" path="/sdk/v1/iace/mitigations/:mid/verify" description="Massnahme als verifiziert markieren" />
      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/validate-mitigation-hierarchy" description="3-Stufen-Hierarchie validieren" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/validate-mitigation-hierarchy" \\
  -H "Authorization: Bearer YOUR_API_KEY"`}
      </CodeBlock>

      <h3>Response (200 OK)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "valid": false,
    "violations": [
      {
        "hazard_id": "haz_5678",
        "hazard_title": "Quetschgefahr durch Linearantrieb",
        "issue": "Nur Information-Massnahmen vorhanden. Design- oder Schutzmassnahmen muessen vorrangig angewendet werden.",
        "missing_levels": ["design", "protective"]
      }
    ],
    "summary": {
      "total_hazards_with_mitigations": 12,
      "hierarchy_compliant": 9,
      "hierarchy_violations": 3
    }
  }
}`}
      </CodeBlock>

      {/* ============================================================ */}
      {/* EVIDENCE                                                     */}
      {/* ============================================================ */}

      <h2>Evidence</h2>
      <p>Evidenz-Dateien hochladen und verwalten (Pruefberichte, Zertifikate, Fotos, etc.).</p>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/evidence" description="Evidenz-Datei hochladen" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/evidence" \\
  -H "Authorization: Bearer YOUR_API_KEY" \\
  -F "file=@pruefbericht_schutzgitter.pdf" \\
  -F "title=Pruefbericht Schutzgitter ISO 14120" \\
  -F "evidence_type=test_report" \\
  -F "linked_mitigation_id=mit_abcd1234"`}
      </CodeBlock>

      <h3>Response (201 Created)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "id": "evi_xyz789",
    "title": "Pruefbericht Schutzgitter ISO 14120",
    "evidence_type": "test_report",
    "file_name": "pruefbericht_schutzgitter.pdf",
    "file_size": 245760,
    "linked_mitigation_id": "mit_abcd1234",
    "created_at": "2026-03-16T12:00:00Z"
  }
}`}
      </CodeBlock>

      <ApiEndpoint method="GET" path="/sdk/v1/iace/projects/:id/evidence" description="Alle Evidenzen des Projekts auflisten" />

      {/* ============================================================ */}
      {/* VERIFICATION PLANS                                           */}
      {/* ============================================================ */}

      <h2>Verification Plans</h2>
      <p>Verifizierungsplaene erstellen und abarbeiten.</p>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/verification-plan" description="Verifizierungsplan erstellen" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/verification-plan" \\
  -H "Authorization: Bearer YOUR_API_KEY" \\
  -H "Content-Type: application/json" \\
  -d '{
    "title": "Schutzgitter-Verifizierung",
    "description": "Pruefung der Schutzgitter nach ISO 14120",
    "method": "inspection",
    "linked_mitigation_id": "mit_abcd1234",
    "planned_date": "2026-04-15T00:00:00Z"
  }'`}
      </CodeBlock>

      <h3>Response (201 Created)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "id": "vp_plan001",
    "title": "Schutzgitter-Verifizierung",
    "method": "inspection",
    "status": "planned",
    "linked_mitigation_id": "mit_abcd1234",
    "planned_date": "2026-04-15T00:00:00Z",
    "created_at": "2026-03-16T12:30:00Z"
  }
}`}
      </CodeBlock>

      <ApiEndpoint method="PUT" path="/sdk/v1/iace/verification-plan/:vid" description="Verifizierungsplan aktualisieren" />
      <ApiEndpoint method="POST" path="/sdk/v1/iace/verification-plan/:vid/complete" description="Verifizierung abschliessen" />

      {/* ============================================================ */}
      {/* CE TECHNICAL FILE                                            */}
      {/* ============================================================ */}

      <h2>CE Technical File</h2>
      <p>
        LLM-gestuetzte Generierung der Technischen Dokumentation (CE Technical File).
        Die API generiert alle erforderlichen Abschnitte basierend auf den Projektdaten.
      </p>

      <InfoBox type="info" title="LLM-Generierung">
        Die Generierung verwendet einen LLM-Service (qwen3:30b-a3b oder claude-sonnet-4-5)
        fuer kontextbasierte Texterstellung. Alle generierten Abschnitte muessen vor der
        Freigabe manuell geprueft werden (Human Oversight).
      </InfoBox>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/tech-file/generate" description="Alle Tech-File-Abschnitte generieren (LLM-basiert)" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/tech-file/generate" \\
  -H "Authorization: Bearer YOUR_API_KEY"`}
      </CodeBlock>

      <h3>Response (200 OK)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "sections_generated": 8,
    "sections": [
      {
        "section": "general_description",
        "title": "Allgemeine Beschreibung",
        "status": "generated",
        "word_count": 450
      },
      {
        "section": "risk_assessment",
        "title": "Risikobeurteilung",
        "status": "generated",
        "word_count": 1200
      },
      {
        "section": "safety_requirements",
        "title": "Sicherheitsanforderungen",
        "status": "generated",
        "word_count": 800
      },
      {
        "section": "verification_results",
        "title": "Verifizierungsergebnisse",
        "status": "generated",
        "word_count": 600
      }
    ],
    "total_word_count": 4850,
    "generation_time_ms": 12500
  }
}`}
      </CodeBlock>

      <ApiEndpoint method="GET" path="/sdk/v1/iace/projects/:id/tech-file" description="Alle Tech-File-Abschnitte auflisten" />
      <ApiEndpoint method="PUT" path="/sdk/v1/iace/projects/:id/tech-file/:section" description="Abschnitt-Inhalt manuell aktualisieren" />
      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/tech-file/:section/approve" description="Abschnitt freigeben (Human Oversight)" />
      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/tech-file/:section/generate" description="Einzelnen Abschnitt (neu) generieren via LLM" />

      <ApiEndpoint method="GET" path="/sdk/v1/iace/projects/:id/tech-file/export?format=pdf|xlsx|docx|md|json" description="Tech File exportieren" />

      <h3>Export-Formate</h3>
      <ParameterTable
        parameters={[
          { name: 'format', type: 'string', required: true, description: 'Export-Format: "pdf", "xlsx", "docx", "md", "json"' },
        ]}
      />

      <CodeBlock language="bash" filename="cURL">
{`# PDF Export
curl -X GET "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/tech-file/export?format=pdf" \\
  -H "Authorization: Bearer YOUR_API_KEY" \\
  -o technical-file.pdf

# Markdown Export
curl -X GET "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/tech-file/export?format=md" \\
  -H "Authorization: Bearer YOUR_API_KEY" \\
  -o technical-file.md`}
      </CodeBlock>

      {/* ============================================================ */}
      {/* MONITORING                                                   */}
      {/* ============================================================ */}

      <h2>Monitoring</h2>
      <p>Post-Market-Surveillance: Monitoring-Ereignisse erfassen und verfolgen.</p>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/monitoring" description="Monitoring-Ereignis erstellen" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/monitoring" \\
  -H "Authorization: Bearer YOUR_API_KEY" \\
  -H "Content-Type: application/json" \\
  -d '{
    "event_type": "incident",
    "title": "Schutzgitter-Sensor Fehlausloesung",
    "description": "Sicherheitssensor hat ohne erkennbaren Grund ausgeloest",
    "severity": "medium",
    "occurred_at": "2026-03-15T14:30:00Z"
  }'`}
      </CodeBlock>

      <h3>Response (201 Created)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "id": "mon_evt001",
    "event_type": "incident",
    "title": "Schutzgitter-Sensor Fehlausloesung",
    "severity": "medium",
    "status": "open",
    "occurred_at": "2026-03-15T14:30:00Z",
    "created_at": "2026-03-16T08:00:00Z"
  }
}`}
      </CodeBlock>

      <ApiEndpoint method="GET" path="/sdk/v1/iace/projects/:id/monitoring" description="Monitoring-Ereignisse auflisten" />
      <ApiEndpoint method="PUT" path="/sdk/v1/iace/projects/:id/monitoring/:eid" description="Monitoring-Ereignis aktualisieren" />

      {/* ============================================================ */}
      {/* LIBRARIES (PROJECT-INDEPENDENT)                              */}
      {/* ============================================================ */}

      <h2>Libraries (projektunabhaengig)</h2>
      <p>
        Stammdaten-Bibliotheken fuer die Gefahrenanalyse. Diese Endpoints sind
        projektunabhaengig und liefern die Referenzdaten fuer die gesamte IACE-Engine.
      </p>

      <ApiEndpoint method="GET" path="/sdk/v1/iace/hazard-library" description="Gefahrenbibliothek (102 Eintraege)" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X GET "https://api.breakpilot.io/sdk/v1/iace/hazard-library" \\
  -H "Authorization: Bearer YOUR_API_KEY"`}
      </CodeBlock>

      <h3>Response (200 OK)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": [
    {
      "id": "HP001",
      "title": "Crushing hazard from closing mechanisms",
      "category": "mechanical",
      "iso_reference": "ISO 12100 Anhang A.1",
      "typical_components": ["actuator", "press", "clamp"],
      "severity_range": "medium-critical"
    },
    {
      "id": "HP045",
      "title": "Electric shock from exposed conductors",
      "category": "electrical",
      "iso_reference": "ISO 12100 Anhang A.2",
      "typical_components": ["power_supply", "motor", "controller"],
      "severity_range": "high-critical"
    }
  ],
  "meta": {
    "total": 102,
    "categories": {
      "mechanical": 28,
      "electrical": 15,
      "thermal": 10,
      "noise": 8,
      "vibration": 7,
      "radiation": 9,
      "materials": 12,
      "ergonomic": 13
    }
  }
}`}
      </CodeBlock>

      <ApiEndpoint method="GET" path="/sdk/v1/iace/controls-library" description="Controls-Bibliothek" />
      <ApiEndpoint method="GET" path="/sdk/v1/iace/component-library" description="Komponentenbibliothek (C001-C120)" />
      <ApiEndpoint method="GET" path="/sdk/v1/iace/energy-sources" description="Energiequellen (EN01-EN20)" />
      <ApiEndpoint method="GET" path="/sdk/v1/iace/lifecycle-phases" description="ISO 12100 Lebenszyklusphasen" />
      <ApiEndpoint method="GET" path="/sdk/v1/iace/roles" description="Betroffene Personenrollen" />
      <ApiEndpoint method="GET" path="/sdk/v1/iace/evidence-types" description="Evidenz-Typen" />
      <ApiEndpoint method="GET" path="/sdk/v1/iace/protective-measures-library" description="Schutzmassnahmen-Bibliothek" />
      <ApiEndpoint method="GET" path="/sdk/v1/iace/hazard-patterns" description="Hazard-Pattern-Katalog" />
      <ApiEndpoint method="GET" path="/sdk/v1/iace/tags" description="Tag-Taxonomie" />

      {/* ============================================================ */}
      {/* AUDIT TRAIL                                                  */}
      {/* ============================================================ */}

      <h2>Audit Trail</h2>
      <p>Lueckenloser Audit-Trail aller Projektaenderungen fuer Compliance-Nachweise.</p>

      <ApiEndpoint method="GET" path="/sdk/v1/iace/projects/:id/audit-trail" description="Projekt-Audit-Trail abrufen" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X GET "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/audit-trail" \\
  -H "Authorization: Bearer YOUR_API_KEY"`}
      </CodeBlock>

      <h3>Response (200 OK)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": [
    {
      "id": "aud_001",
      "action": "hazard_created",
      "entity_type": "hazard",
      "entity_id": "haz_5678",
      "user_id": "user_abc",
      "changes": {
        "title": "Quetschgefahr durch Linearantrieb",
        "severity": "high"
      },
      "timestamp": "2026-03-16T10:15:00Z"
    },
    {
      "id": "aud_002",
      "action": "risk_assessed",
      "entity_type": "hazard",
      "entity_id": "haz_5678",
      "user_id": "user_abc",
      "changes": {
        "inherent_risk": 12,
        "risk_level": "high"
      },
      "timestamp": "2026-03-16T10:20:00Z"
    },
    {
      "id": "aud_003",
      "action": "tech_file_section_approved",
      "entity_type": "tech_file",
      "entity_id": "risk_assessment",
      "user_id": "user_def",
      "changes": {
        "status": "approved",
        "approved_by": "Dr. Mueller"
      },
      "timestamp": "2026-03-16T15:00:00Z"
    }
  ]
}`}
      </CodeBlock>

      {/* ============================================================ */}
      {/* RAG LIBRARY SEARCH                                           */}
      {/* ============================================================ */}

      <h2>RAG Library Search</h2>
      <p>
        Semantische Suche in der Compliance-Bibliothek via RAG (Retrieval-Augmented Generation).
        Ermoeglicht kontextbasierte Anreicherung von Tech-File-Abschnitten.
      </p>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/library-search" description="Compliance-Bibliothek via RAG durchsuchen" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/library-search" \\
  -H "Authorization: Bearer YOUR_API_KEY" \\
  -H "Content-Type: application/json" \\
  -d '{
    "query": "Schutzeinrichtungen fuer Industrieroboter Maschinenverordnung",
    "top_k": 5
  }'`}
      </CodeBlock>

      <h3>Response (200 OK)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "query": "Schutzeinrichtungen fuer Industrieroboter Maschinenverordnung",
    "results": [
      {
        "id": "mr-annex-iii-1.1.4",
        "title": "Maschinenverordnung Anhang III 1.1.4 — Schutzmassnahmen",
        "content": "Trennende Schutzeinrichtungen muessen fest angebracht oder verriegelt sein...",
        "source": "machinery_regulation",
        "score": 0.93
      }
    ],
    "total_results": 5,
    "search_time_ms": 38
  }
}`}
      </CodeBlock>

      <ApiEndpoint method="POST" path="/sdk/v1/iace/projects/:id/tech-file/:section/enrich" description="Tech-File-Abschnitt mit RAG-Kontext anreichern" />

      <CodeBlock language="bash" filename="cURL">
{`curl -X POST "https://api.breakpilot.io/sdk/v1/iace/projects/proj_a1b2c3d4/tech-file/safety_requirements/enrich" \\
  -H "Authorization: Bearer YOUR_API_KEY"`}
      </CodeBlock>

      <h3>Response (200 OK)</h3>
      <CodeBlock language="json" filename="Response">
{`{
  "success": true,
  "data": {
    "section": "safety_requirements",
    "enriched_content": "... (aktualisierter Abschnitt mit Regulierungsreferenzen) ...",
    "citations_added": 4,
    "sources": [
      {
        "id": "mr-annex-iii-1.1.4",
        "title": "Maschinenverordnung Anhang III 1.1.4",
        "relevance_score": 0.93
      }
    ]
  }
}`}
      </CodeBlock>

      {/* ============================================================ */}
      {/* SDK INTEGRATION                                              */}
      {/* ============================================================ */}

      <h2>SDK Integration</h2>
      <p>
        Beispiel fuer die Integration der IACE-API in eine Anwendung:
      </p>

      <CodeBlock language="typescript" filename="iace-workflow.ts">
{`import { getSDKBackendClient } from '@breakpilot/compliance-sdk'

const client = getSDKBackendClient()

// 1. Projekt erstellen
const project = await client.post('/iace/projects', {
  machine_name: 'RoboArm X500',
  machine_type: 'Industrieroboter',
  manufacturer: 'TechCorp GmbH'
})

// 2. Aus Firmenprofil initialisieren
await client.post(\`/iace/projects/\${project.id}/init-from-profile\`)

// 3. Komponenten hinzufuegen
await client.post(\`/iace/projects/\${project.id}/components\`, {
  name: 'Servo-Antrieb Achse 1',
  component_type: 'actuator',
  is_safety_relevant: true
})

// 4. Regulierungen klassifizieren
const classifications = await client.post(
  \`/iace/projects/\${project.id}/classify\`
)

// 5. Pattern-Matching ausfuehren
const patterns = await client.post(
  \`/iace/projects/\${project.id}/match-patterns\`
)
console.log(\`\${patterns.matches} Gefahren erkannt von \${patterns.total_patterns_checked} Patterns\`)

// 6. Erkannte Patterns als Gefahren uebernehmen
await client.post(\`/iace/projects/\${project.id}/apply-patterns\`)

// 7. Risiken bewerten
for (const hazard of await client.get(\`/iace/projects/\${project.id}/hazards\`)) {
  await client.post(\`/iace/projects/\${project.id}/hazards/\${hazard.id}/assess\`, {
    severity: 3, exposure: 2, probability: 2, avoidance: 2
  })
}

// 8. Tech File generieren
const techFile = await client.post(
  \`/iace/projects/\${project.id}/tech-file/generate\`
)
console.log(\`\${techFile.sections_generated} Abschnitte generiert\`)

// 9. PDF exportieren
const pdf = await client.get(
  \`/iace/projects/\${project.id}/tech-file/export?format=pdf\`
)
`}
      </CodeBlock>

      <InfoBox type="warning" title="Rate Limits &amp; LLM-Kosten">
        LLM-basierte Endpoints (Tech-File-Generierung, Hazard-Suggest, RAG-Enrichment)
        verbrauchen LLM-Tokens. Professional-Plan: 50 Generierungen/Tag.
        Enterprise-Plan: unbegrenzt. Implementieren Sie Caching fuer wiederholte Anfragen.
      </InfoBox>

      <InfoBox type="success" title="Human Oversight">
        Alle LLM-generierten Inhalte muessen vor der Freigabe manuell geprueft werden.
        Die API erzwingt dies ueber den Approve-Workflow: generierte Abschnitte haben
        den Status &quot;generated&quot; und muessen explizit auf &quot;approved&quot; gesetzt werden.
      </InfoBox>
    </DevPortalLayout>
  )
}
