{
  "openapi": "3.1.0",
  "info": {
    "title": "Clea Clinic API",
    "version": "1.0.0",
    "description": "Read-only clinic integration API for patient-authorised Clea handoffs and booking workflow. Production access is provider-bound and scope-limited."
  },
  "servers": [
    {
      "url": "https://www.cleamigraine.com.au/_api"
    }
  ],
  "components": {
    "securitySchemes": {
      "ClinicBearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Clea clinic token"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "CareSnapshot": {
        "type": "object",
        "description": "Frozen patient-authorised care snapshot. The clinic receives only sections explicitly shared by the member.",
        "properties": {
          "memberName": {
            "type": [
              "string",
              "null"
            ]
          },
          "memberEmail": {
            "type": [
              "string",
              "null"
            ],
            "format": "email"
          },
          "goal": {
            "type": "string"
          },
          "symptoms": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "treatmentsText": {
            "type": [
              "string",
              "null"
            ]
          },
          "accessPreference": {
            "type": [
              "string",
              "null"
            ]
          },
          "postcode": {
            "type": [
              "string",
              "null"
            ]
          },
          "referralStatus": {
            "type": [
              "string",
              "null"
            ]
          },
          "sharedSections": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "capturedAt": {
            "type": "string",
            "format": "date-time"
          },
          "version": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/clinic-api": {
      "get": {
        "summary": "Read authorised clinic resources",
        "security": [
          {
            "ClinicBearer": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "resource",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "meta",
                "handoffs",
                "bookings"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Clinic-scoped resource response"
          },
          "401": {
            "description": "Invalid token"
          },
          "403": {
            "description": "Scope or integration not enabled"
          }
        }
      }
    },
    "/clinic-fhir": {
      "get": {
        "summary": "Read one patient-authorised handoff as FHIR-aligned JSON",
        "security": [
          {
            "ClinicBearer": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "handoffId",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "FHIR Bundle",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "Handoff unavailable or consent withdrawn"
          }
        }
      }
    }
  },
  "x-clea-webhooks": {
    "description": "Signed webhook notifications contain resource IDs only. Authenticate to the Clinic API to retrieve the authorised resource.",
    "events": [
      "handoff.created",
      "handoff.updated",
      "booking.created",
      "booking.updated",
      "integration.test"
    ],
    "headers": [
      "webhook-id",
      "webhook-timestamp",
      "webhook-signature"
    ]
  }
}