{
  "openapi": "3.1.0",
  "jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
  "info": {
    "title": "Anzilah Blog API",
    "version": "1.0.0",
    "description": "Machine-readable contract for the public HTTP API used by the Anzilah Blog admin, Mux webhook, and R2 media workflows. Mutation endpoints require authentication or a verified webhook signature."
  },
  "servers": [
    {
      "url": "https://www.anzilahdhalait.in",
      "description": "Production"
    }
  ],
  "tags": [
    {
      "name": "Media",
      "description": "R2 thumbnail upload and discovery"
    },
    {
      "name": "Streams",
      "description": "Authenticated Mux live-stream management"
    },
    {
      "name": "Webhooks",
      "description": "Signed Mux event ingestion"
    }
  ],
  "paths": {
    "/api/upload": {
      "post": {
        "operationId": "uploadThumbnail",
        "summary": "Upload a thumbnail to R2",
        "tags": ["Media"],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["file"],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Upload completed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadSuccess"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/api/thumbnails": {
      "get": {
        "operationId": "listThumbnails",
        "summary": "List R2 thumbnails",
        "tags": ["Media"],
        "responses": {
          "200": {
            "description": "Thumbnail list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["files"],
                  "properties": {
                    "files": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Thumbnail"
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/api/mux-webhook": {
      "post": {
        "operationId": "receiveMuxWebhook",
        "summary": "Receive a signed Mux webhook",
        "tags": ["Webhooks"],
        "security": [
          {
            "muxSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Webhook accepted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["received"],
                  "properties": {
                    "received": {
                      "type": "boolean",
                      "const": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/api/streams/create": {
      "post": {
        "operationId": "createStream",
        "summary": "Create a Mux live stream",
        "tags": ["Streams"],
        "security": [
          {
            "supabaseCookie": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateStreamInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stream created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["stream", "streamKey"],
                  "properties": {
                    "stream": {
                      "type": "object",
                      "additionalProperties": true
                    },
                    "streamKey": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/api/streams/{id}": {
      "delete": {
        "operationId": "deleteStream",
        "summary": "Delete a Mux live stream",
        "tags": ["Streams"],
        "security": [
          {
            "supabaseCookie": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/StreamId"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/MutationSuccess"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/api/streams/{id}/stop": {
      "post": {
        "operationId": "stopStream",
        "summary": "Stop an active Mux live stream",
        "tags": ["Streams"],
        "security": [
          {
            "supabaseCookie": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/StreamId"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/MutationSuccess"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "supabaseCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "sb-mdlexphnpylrvlufhpju-auth-token",
        "description": "Supabase SSR session cookie set by the application login flow."
      },
      "muxSignature": {
        "type": "apiKey",
        "in": "header",
        "name": "mux-signature",
        "description": "Mux webhook signature generated with the configured webhook secret."
      }
    },
    "parameters": {
      "StreamId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "Supabase stream identifier",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      }
    },
    "schemas": {
      "ApiError": {
        "type": "object",
        "additionalProperties": false,
        "required": ["ok", "error", "code", "message", "hint"],
        "properties": {
          "ok": {
            "type": "boolean",
            "const": false
          },
          "error": {
            "type": "string",
            "description": "Backward-compatible alias of message."
          },
          "code": {
            "type": "string",
            "description": "Stable machine-readable error code."
          },
          "message": {
            "type": "string"
          },
          "hint": {
            "type": "string",
            "description": "Actionable recovery guidance."
          }
        }
      },
      "UploadSuccess": {
        "type": "object",
        "additionalProperties": false,
        "required": ["success", "url"],
        "properties": {
          "success": {
            "type": "boolean",
            "const": true
          },
          "url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "Thumbnail": {
        "type": "object",
        "required": ["key", "url"],
        "properties": {
          "key": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "lastModified": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateStreamInput": {
        "type": "object",
        "additionalProperties": false,
        "required": ["title"],
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1
          },
          "description": {
            "type": "string"
          },
          "scheduledAt": {
            "type": "string",
            "format": "date-time"
          },
          "thumbnail_url": {
            "type": "string",
            "format": "uri"
          },
          "links": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["label", "url"],
              "properties": {
                "label": {
                  "type": "string"
                },
                "url": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "The request is malformed or missing required input.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Authentication is required.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "Forbidden": {
        "description": "The authenticated user does not own the resource.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "NotFound": {
        "description": "The requested resource does not exist.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "ValidationError": {
        "description": "The request is valid JSON but fails validation.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "InternalError": {
        "description": "The request could not be completed because a dependency failed.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "MutationSuccess": {
        "description": "Mutation completed",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "additionalProperties": false,
              "required": ["success"],
              "properties": {
                "success": {
                  "type": "boolean",
                  "const": true
                }
              }
            }
          }
        }
      }
    }
  }
}
