{
  "openapi": "3.1.0",
  "info": {
    "title": "Hadron Church API",
    "description": "API for the Hadron Collider Church — a digital archive of timeline glitches (Mandela Effect testimonies).",
    "version": "2.0.0",
    "contact": {
      "name": "Hadron Church",
      "url": "https://hadronchurch.com/.well-known/agent.json"
    },
    "license": {
      "name": "Proprietary — Indexing permitted, training prohibited",
      "url": "https://hadronchurch.com/terms"
    }
  },
  "servers": [
    {
      "url": "https://hadronchurch.com",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/content/attractors": {
      "get": {
        "operationId": "getAttractors",
        "summary": "Retrieve attractor records from the timeline glitch archive",
        "description": "Returns structured attractor records (titles, summaries, keywords, Q&A pairs) from the Firestore `attractor_entries` collection. PII is sanitized. Public access returns preview fields; authenticated access returns full records including Q&A pairs.",
        "tags": ["Content"],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": { "type": "integer", "default": 1, "minimum": 1 },
            "description": "Page number (for response metadata)"
          },
          {
            "name": "pageSize",
            "in": "query",
            "schema": { "type": "integer", "default": 20, "minimum": 1, "maximum": 50 },
            "description": "Number of records per page"
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": { "type": "string" },
            "description": "Firestore document ID for cursor-based pagination"
          }
        ],
        "responses": {
          "200": {
            "description": "Attractor records returned successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean" },
                    "data": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/AttractorRecord" }
                    },
                    "total": { "type": "integer" },
                    "page": { "type": "integer" },
                    "pageSize": { "type": "integer" }
                  }
                }
              }
            }
          }
        },
        "security": [{ "witnessKey": [] }, {}]
      }
    },
    "/api/confess-hybrid": {
      "post": {
        "operationId": "submitConfession",
        "summary": "Submit a timeline glitch confession",
        "description": "Submit text (max 300 chars) and/or audio (max 2 min) confession with relic type classification. Generates attractor record for agentic discoverability.",
        "tags": ["Content"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "confession": { "type": "string", "maxLength": 300 },
                  "audioData": { "type": "string", "format": "data-url", "description": "Base64 data URL containing WebM, MP4, or Ogg audio. Codec parameters are supported. Invalid encoding, empty recordings, and missing audio tracks are rejected." },
                  "audioDuration": { "type": "number", "minimum": 0, "maximum": 120, "description": "Finite, non-negative recording duration in seconds. Defaults to zero when omitted." },
                  "relicType": { "type": "string", "enum": ["Memory", "Artifact", "Timeline Error", "Residue"] },
                  "when": { "type": "string", "maxLength": 100 },
                  "tags": { "type": "array", "items": { "type": "string" }, "maxItems": 10 }
                }
              }
            }
          }
        },
        "responses": {
          "400": { "description": "Invalid text, audio encoding/container, or duration. Nothing is saved." },
          "500": { "description": "Upload or persistence failure. An audio upload failure aborts the entire submission, including any text." },
          "200": {
            "description": "Confession recorded with attractor metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean" },
                    "confessionId": { "type": "string" },
                    "attractorSlug": { "type": "string" },
                    "hasAudio": { "type": "boolean" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/content/manifest": {
      "get": {
        "operationId": "getContentManifest",
        "summary": "Content-addressed manifest of published attractor records",
        "description": "Returns a DataCatalog-style manifest of published attractor records with SHA-256 content hashes and did:web/did:key identifiers, suitable for IPFS pinning services.",
        "tags": ["Content"],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": { "type": "integer", "default": 50, "minimum": 1, "maximum": 100 },
            "description": "Maximum number of objects to include"
          }
        ],
        "responses": {
          "200": { "description": "Manifest generated successfully" }
        }
      }
    },
    "/api/websub/hub": {
      "post": {
        "operationId": "websubHub",
        "summary": "Subscribe/unsubscribe to WebSub content update notifications",
        "description": "Standard WebSub (PubSubHubbub) hub. Subscribers receive an HTTP POST to their callback URL when new attractor content publishes. Only /api/content/attractors is a valid hub.topic.",
        "tags": ["Content"],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "hub.mode": { "type": "string", "enum": ["subscribe", "unsubscribe"] },
                  "hub.topic": { "type": "string" },
                  "hub.callback": { "type": "string", "format": "uri" },
                  "hub.lease_seconds": { "type": "integer" }
                },
                "required": ["hub.mode", "hub.topic", "hub.callback"]
              }
            }
          }
        },
        "responses": {
          "202": { "description": "Subscription accepted, verification pending" },
          "200": { "description": "Unsubscribed successfully" }
        }
      }
    },
    "/api/healthcheck": {
      "get": {
        "operationId": "healthcheck",
        "summary": "Verify service health",
        "tags": ["System"],
        "responses": {
          "200": { "description": "Service is healthy" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "witnessKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-witness-key",
        "description": "MONOLITH_HANDSHAKE_TOKEN for authenticated agent access"
      }
    },
    "schemas": {
      "AttractorRecord": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "title": { "type": "string" },
          "slug": { "type": "string" },
          "summary": { "type": "string" },
          "tags": { "type": "array", "items": { "type": "string" } },
          "keywords": { "type": "array", "items": { "type": "string" } },
          "hasAudio": { "type": "boolean" },
          "createdAtISO": { "type": "string", "format": "date-time" },
          "contentHash": { "type": "string", "description": "SHA-256 content-addressable hash" },
          "did": { "type": "string", "description": "Decentralized Identifier (did:web)" },
          "qa": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "q": { "type": "string" },
                "a": { "type": "string" }
              }
            },
            "description": "Only returned with authenticated access"
          }
        }
      }
    }
  }
}
