import type { SystemInfoConfig } from './types'

export const middlewareConfig: SystemInfoConfig = {
  title: 'Middleware System-Info',
  description: 'Middleware-Stack mit Test-Wizard fuer Integration Tests.',
  version: '1.5',
  architecture: {
    layers: [
      { title: 'Test Wizard UI', components: ['Test Runner', 'Result Viewer', 'Coverage Report'], color: '#3b82f6' },
      { title: 'API Gateway', components: ['Traefik', 'Rate Limiter', 'Auth Proxy'], color: '#8b5cf6' },
      { title: 'Services', components: ['Consent', 'Klausur', 'School', 'Backend'], color: '#10b981' },
      { title: 'Infrastructure', components: ['PostgreSQL', 'Valkey', 'MinIO', 'Qdrant'], color: '#f59e0b' },
    ],
  },
  features: [
    { name: 'Integration Tests', status: 'active', description: 'End-to-End API Tests' },
    { name: 'Health Checks', status: 'active', description: 'Service-Status Pruefung' },
    { name: 'Test Wizard', status: 'active', description: 'Interaktive Test-Suite' },
    { name: 'Load Testing', status: 'planned', description: 'Performance-Tests' },
    { name: 'Chaos Engineering', status: 'planned', description: 'Resilienz-Tests' },
  ],
  roadmap: [
    { phase: 'Phase 1: Testing (Q1)', priority: 'high', items: ['API Test Suite', 'Database Tests', 'Auth Flow Tests', 'Error Handling Tests'] },
    { phase: 'Phase 2: Performance (Q2)', priority: 'medium', items: ['k6 Load Tests', 'Latency Benchmarks', 'Throughput Tests', 'Memory Profiling'] },
    { phase: 'Phase 3: Resilience (Q3)', priority: 'low', items: ['Chaos Monkey', 'Failover Tests', 'Circuit Breaker', 'Graceful Degradation'] },
  ],
  technicalDetails: [
    { component: 'API Gateway', technology: 'Traefik', version: '3.x', description: 'Reverse Proxy' },
    { component: 'Cache', technology: 'Valkey', version: '8.x', description: 'In-Memory Store' },
    { component: 'Storage', technology: 'MinIO', version: 'Latest', description: 'S3-kompatibel' },
    { component: 'Vector DB', technology: 'Qdrant', version: '1.12+', description: 'Similarity Search' },
  ],
  auditInfo: [
    {
      category: 'Service Health',
      items: [
        { label: 'API Gateway (Traefik)', value: 'Online', status: 'ok' },
        { label: 'PostgreSQL', value: 'Online', status: 'ok' },
        { label: 'Valkey (Cache)', value: 'Online', status: 'ok' },
        { label: 'Qdrant', value: 'Online', status: 'ok' },
      ],
    },
    {
      category: 'Test Coverage',
      items: [
        { label: 'Integration Tests', value: 'Aktiv', status: 'ok' },
        { label: 'Auth Flow Tests', value: 'Implementiert', status: 'ok' },
        { label: 'Load Tests', value: 'Geplant', status: 'warning' },
        { label: 'Chaos Tests', value: 'Geplant', status: 'warning' },
      ],
    },
    {
      category: 'Performance',
      items: [
        { label: 'Avg. Response Time', value: '< 100ms', status: 'ok' },
        { label: 'Uptime (30 Tage)', value: '> 99.9%', status: 'ok' },
        { label: 'Error Rate', value: '< 0.1%', status: 'ok' },
        { label: 'Cache Hit Ratio', value: '> 90%', status: 'ok' },
      ],
    },
  ],
  fullDocumentation: `
<h2>Middleware & Integration Testing</h2>

<h3>1. Uebersicht</h3>
<p>Das Middleware-Modul verwaltet den gesamten Service-Stack und bietet einen Test-Wizard fuer Integration Tests. Es stellt sicher, dass alle Services korrekt miteinander kommunizieren.</p>

<h3>2. Service-Architektur</h3>
<pre>
┌─────────────────────────────────────────────────────────────────────┐
│                          Traefik Gateway                             │
│  ├── TLS Termination                                                │
│  ├── Rate Limiting                                                  │
│  ├── Request Routing                                                │
│  └── Health Checks                                                  │
└────────────────────────────────┬────────────────────────────────────┘
                                 │
          ┌──────────────────────┼──────────────────────┐
          │                      │                      │
          v                      v                      v
┌─────────────────┐   ┌─────────────────┐   ┌─────────────────┐
│  Website (3000) │   │  Backend (8000) │   │ Consent (8081)  │
│    Next.js      │   │    FastAPI      │   │      Gin        │
└────────┬────────┘   └────────┬────────┘   └────────┬────────┘
         │                     │                     │
         └──────────────────┬──┴─────────────────────┘
                            │
          ┌─────────────────┼─────────────────┐
          │                 │                 │
          v                 v                 v
┌─────────────────┐  ┌────────────┐  ┌─────────────────┐
│   PostgreSQL    │  │   Valkey   │  │     Qdrant      │
│     (5432)      │  │   (6379)   │  │     (6333)      │
└─────────────────┘  └────────────┘  └─────────────────┘
</pre>

<h3>3. Test-Wizard Funktionen</h3>
<table>
  <tr><th>Test-Kategorie</th><th>Beschreibung</th><th>Status</th></tr>
  <tr><td>Health Checks</td><td>Service-Erreichbarkeit</td><td>Automatisch</td></tr>
  <tr><td>Auth Flow</td><td>Login, Token-Refresh, Logout</td><td>Implementiert</td></tr>
  <tr><td>Consent CRUD</td><td>Dokumente erstellen, lesen, aktualisieren</td><td>Implementiert</td></tr>
  <tr><td>Database</td><td>Connection Pool, Query Performance</td><td>Implementiert</td></tr>
  <tr><td>Cache</td><td>Set/Get, Invalidierung</td><td>Implementiert</td></tr>
  <tr><td>Vector Search</td><td>Embedding, Similarity Search</td><td>Implementiert</td></tr>
</table>

<h3>4. API Endpoints</h3>
<table>
  <tr><th>Endpoint</th><th>Methode</th><th>Beschreibung</th></tr>
  <tr><td>/api/middleware/health</td><td>GET</td><td>Alle Service Health Checks</td></tr>
  <tr><td>/api/middleware/tests</td><td>GET</td><td>Verfuegbare Test-Suites</td></tr>
  <tr><td>/api/middleware/tests/run</td><td>POST</td><td>Test-Suite ausfuehren</td></tr>
  <tr><td>/api/middleware/metrics</td><td>GET</td><td>Performance-Metriken</td></tr>
</table>

<h3>5. Health Check Format</h3>
<pre>
{
  "status": "healthy",
  "timestamp": "2025-01-14T10:00:00Z",
  "services": {
    "postgres": {
      "status": "up",
      "latency_ms": 2,
      "details": {"connections": 10, "max": 100}
    },
    "valkey": {
      "status": "up",
      "latency_ms": 1,
      "details": {"memory_used": "50MB"}
    },
    "qdrant": {
      "status": "up",
      "latency_ms": 5,
      "details": {"collections": 3}
    }
  }
}
</pre>

<h3>6. Test-Ausfuehrung</h3>
<pre>
Test Request
     │
     v
┌───────────────────────────────────────┐
│         Test Runner Engine            │
├───────────────────────────────────────┤
│  1. Setup (Fixtures, Test Data)       │
│  2. Execute (Sequential/Parallel)     │
│  3. Assert (Expected vs Actual)       │
│  4. Cleanup (Remove Test Data)        │
│  5. Report (Results, Timings)         │
└───────────────────────────────────────┘
     │
     v
┌───────────────────────────────────────┐
│           Test Report                  │
│  ├── Total: 25, Passed: 24, Failed: 1 │
│  ├── Duration: 5.2s                   │
│  └── Details per Test Case            │
└───────────────────────────────────────┘
</pre>

<h3>7. Rate Limiting</h3>
<table>
  <tr><th>Endpoint-Typ</th><th>Limit</th><th>Window</th></tr>
  <tr><td>Public API</td><td>100 req</td><td>1 Minute</td></tr>
  <tr><td>Authenticated API</td><td>1000 req</td><td>1 Minute</td></tr>
  <tr><td>Admin API</td><td>5000 req</td><td>1 Minute</td></tr>
  <tr><td>File Upload</td><td>10 req</td><td>1 Minute</td></tr>
</table>

<h3>8. Caching-Strategie</h3>
<ul>
  <li><strong>Session Cache:</strong> 15 Min TTL, User-Tokens</li>
  <li><strong>API Response Cache:</strong> 5 Min TTL, GET-Requests</li>
  <li><strong>Config Cache:</strong> 1 Stunde TTL, System-Konfiguration</li>
  <li><strong>Invalidierung:</strong> Event-basiert bei Datenänderung</li>
</ul>

<h3>9. Monitoring & Alerts</h3>
<table>
  <tr><th>Alert</th><th>Schwelle</th><th>Aktion</th></tr>
  <tr><td>Service Down</td><td>3 failed checks</td><td>PagerDuty, Slack</td></tr>
  <tr><td>High Latency</td><td>> 500ms avg</td><td>Slack</td></tr>
  <tr><td>High Error Rate</td><td>> 1%</td><td>Slack</td></tr>
  <tr><td>DB Connections High</td><td>> 80%</td><td>E-Mail</td></tr>
</table>

<h3>10. Troubleshooting</h3>
<pre>
Problem: Service nicht erreichbar
├── Check: Docker Container Status
├── Check: Port-Mapping
├── Check: Network (docker network ls)
└── Check: Logs (docker logs service-name)

Problem: Hohe Latenz
├── Check: Database Query Performance
├── Check: Cache Hit Ratio
├── Check: CPU/Memory Usage
└── Check: Network Latency
</pre>
`,
}
