'use client'

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

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