'use client'

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

export function MitigationsSection() {
  return (
    <>
      <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>
    </>
  )
}
