{
  "openapi": "3.1.0",
  "info": {
    "title": "Argos Eyes API",
    "version": "1.0.0",
    "description": "Argos Eyes — alerting + automated incident management for MSPs/MSSPs.\n\nAll authenticated routes require either a service token (X-Argos-Service-Token header) or a Zitadel-issued JWT (Authorization: Bearer …). Service tokens have explicit scopes; JWTs carry tenant + role claims.",
    "contact": {
      "name": "Intelligent Automation",
      "url": "https://intelamation.com",
      "email": "info@intelamation.com"
    },
    "license": { "name": "Proprietary", "identifier": "LicenseRef-Intelamation-Proprietary" }
  },
  "servers": [
    { "url": "https://alert.intelamation.net", "description": "Production" }
  ],
  "tags": [
    { "name": "Ingest", "description": "Inbound webhook + JSON alert ingest" },
    { "name": "Incidents", "description": "Incident CRUD + lifecycle transitions" },
    { "name": "Alerts", "description": "Raw alert lookup" },
    { "name": "Runbooks", "description": "Runbook management + execution" },
    { "name": "AI", "description": "Claude-backed summarization, runbook suggestion, classification" },
    { "name": "Status Pages", "description": "Public + admin status page surfaces (Phase 6)" },
    { "name": "Health", "description": "Liveness + readiness" }
  ],
  "paths": {
    "/healthz": {
      "get": {
        "tags": ["Health"],
        "summary": "Liveness + dependency probes",
        "responses": { "200": { "description": "OK" }, "503": { "description": "Dependency unavailable" } }
      }
    },
    "/v1/ingest/{slug}": {
      "post": {
        "tags": ["Ingest"],
        "summary": "Per-integration HMAC-signed webhook ingest",
        "description": "Vendor-specific inbound webhook. The slug resolves to an integrations_inbound row which carries the kind (prometheus, sentinel, datadog, sophos, …) and a Vault pointer to the HMAC verification key. Body is dispatched to the matching connector parser, normalized to NormalizedAlert(s), routed through the dedup engine.",
        "parameters": [
          { "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "X-Signature-HMAC-SHA256", "in": "header", "required": true, "schema": { "type": "string" }, "description": "Hex digest, optionally prefixed sha256=, of HMAC-SHA256(vault_key, raw_body)" }
        ],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "type": "object", "additionalProperties": true } } }
        },
        "responses": {
          "202": { "description": "Accepted (one or more alerts ingested or merged)" },
          "401": { "description": "Missing or invalid HMAC signature" },
          "403": { "description": "Integration disabled" },
          "404": { "description": "Unknown integration slug" },
          "429": { "description": "All alerts flood-dropped" }
        }
      }
    },
    "/v1/alerts/ingest": {
      "post": {
        "tags": ["Ingest"],
        "summary": "Spec'd internal JSON ingest (already-normalized)",
        "description": "For callers that already produce alerts in our internal shape. Requires service token with alerts:ingest scope OR an admin JWT.",
        "security": [{ "ServiceToken": [] }, { "BearerJWT": [] }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AlertIngestRequest" } } }
        },
        "responses": { "202": { "description": "Accepted" }, "429": { "description": "Flood-dropped" } }
      }
    },
    "/v1/incidents": {
      "get": {
        "tags": ["Incidents"],
        "summary": "List incidents for caller's tenant",
        "security": [{ "BearerJWT": [] }],
        "parameters": [
          { "name": "state", "in": "query", "schema": { "type": "string", "enum": ["triggered","acknowledged","investigating","mitigated","resolved"] } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 100 } }
        ],
        "responses": { "200": { "description": "Array of incidents" } }
      }
    },
    "/v1/incidents/{id}/ai-summary": {
      "post": {
        "tags": ["AI", "Incidents"],
        "summary": "Generate AI-written handoff brief for an incident",
        "description": "Reads the incident + its constituent alerts + similar past incidents and asks Claude for a structured TLDR / What Happened / Next Steps / Confidence brief. Token usage returned.",
        "security": [{ "BearerJWT": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": {
          "200": { "description": "Structured summary" },
          "429": { "description": "Tenant AI budget exceeded" },
          "502": { "description": "AI upstream error" },
          "503": { "description": "AI not enabled in this deployment" }
        }
      }
    },
    "/v1/incidents/{id}/ai-classify": {
      "post": {
        "tags": ["AI", "Incidents"],
        "summary": "Auto-categorize incident into fixed 8-category taxonomy",
        "description": "Returns category (security|availability|performance|config_change|data_integrity|capacity|third_party_outage|unknown) + subcategory + confidence + rationale + suggested_routing.",
        "security": [{ "BearerJWT": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": { "200": { "description": "Classification" }, "503": { "description": "AI not enabled" } }
      }
    },
    "/v1/alerts/{id}/ai-runbook": {
      "post": {
        "tags": ["AI", "Alerts"],
        "summary": "AI-drafted runbook for an alert",
        "description": "Returns 3-8 step runbook in strict JSON. Destructive steps flagged for two-person approval at execution time. Operator must save the draft as a real runbook template before it can run.",
        "security": [{ "BearerJWT": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": { "200": { "description": "Runbook suggestion" }, "503": { "description": "AI not enabled" } }
      }
    },
    "/v1/runbooks": {
      "get": { "tags": ["Runbooks"], "summary": "List tenant runbooks", "security": [{ "BearerJWT": [] }], "responses": { "200": { "description": "OK" } } },
      "post": { "tags": ["Runbooks"], "summary": "Create runbook", "security": [{ "BearerJWT": [] }], "responses": { "201": { "description": "Created" } } }
    },
    "/v1/status-pages": {
      "get": { "tags": ["Status Pages"], "summary": "List tenant status pages", "security": [{ "BearerJWT": [] }], "responses": { "200": { "description": "OK" } } },
      "post": {
        "tags": ["Status Pages"], "summary": "Create status page",
        "security": [{ "BearerJWT": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CreatePageReq" } } } },
        "responses": { "201": { "description": "Created" }, "409": { "description": "Slug already in use" } }
      }
    },
    "/v1/status-pages/{id}/components": {
      "post": {
        "tags": ["Status Pages"], "summary": "Add component to a status page",
        "security": [{ "BearerJWT": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": { "201": { "description": "Created" } }
      }
    },
    "/v1/status-pages/{id}/components/{cid}/state": {
      "put": {
        "tags": ["Status Pages"], "summary": "Update component state",
        "security": [{ "BearerJWT": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } },
          { "name": "cid", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": { "200": { "description": "OK" }, "404": { "description": "Component not found" } }
      }
    },
    "/public/status/{slug}": {
      "get": {
        "tags": ["Status Pages"], "summary": "Public status JSON (no auth)",
        "description": "Returns overall state + per-component state + recent updates. Cached 30s. Returns 404 for private or unknown pages (no existence leak).",
        "parameters": [{ "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "OK" }, "404": { "description": "Page not found" } }
      }
    },
    "/public/status/{slug}.html": {
      "get": {
        "tags": ["Status Pages"], "summary": "Public status HTML page (no auth)",
        "description": "Argos-OS-branded HTML page with intelamation.com header + footer + MCSP shield. ~16 KB on wire, zero external JS, CSP with per-request nonce.",
        "parameters": [{ "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "HTML page" }, "404": { "description": "Page not found" } }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerJWT":    { "type": "http", "scheme": "bearer", "bearerFormat": "JWT", "description": "Zitadel-issued JWT" },
      "ServiceToken": { "type": "apiKey", "in": "header", "name": "X-Argos-Service-Token" }
    },
    "schemas": {
      "AlertIngestRequest": {
        "type": "object",
        "required": ["source", "title"],
        "properties": {
          "source":      { "type": "string" },
          "source_id":   { "type": "string" },
          "severity":    { "type": "string", "enum": ["critical","high","medium","low","info"] },
          "title":       { "type": "string" },
          "description": { "type": "string" },
          "labels":      { "type": "object", "additionalProperties": { "type": "string" } },
          "fingerprint": { "type": "string" },
          "starts_at":   { "type": "string", "format": "date-time" },
          "raw":         { "type": "object", "additionalProperties": true }
        }
      },
      "CreatePageReq": {
        "type": "object",
        "required": ["slug", "name"],
        "properties": {
          "slug":          { "type": "string", "pattern": "^[a-z][a-z0-9-]{1,38}[a-z0-9]$" },
          "name":          { "type": "string", "minLength": 1, "maxLength": 120 },
          "custom_domain": { "type": "string" },
          "theme":         { "type": "object", "additionalProperties": true },
          "public":        { "type": "boolean", "default": true }
        }
      }
    }
  }
}