{
  "openapi": "3.1.0",
  "info": {
    "title": "OptInFix Public API",
    "version": "1.0.0",
    "description": "Public-facing endpoints for OptInFix — the SMS consent compliance platform for 10DLC and TCPA. Use these endpoints to submit consent, verify a record, and fetch a brand's embed snippet.",
    "contact": {
      "name": "OptInFix Support",
      "email": "support@optinfix.com",
      "url": "https://optinfix.com"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://optinfix.com/terms"
    }
  },
  "servers": [
    {
      "url": "https://yxszujjngrkwrpvtyrdc.supabase.co/functions/v1",
      "description": "Production"
    }
  ],
  "tags": [
    { "name": "Consent", "description": "Capture and verify SMS opt-in consent records." },
    { "name": "Brand", "description": "Brand-level embed and configuration." },
    { "name": "Suppression", "description": "Suppression list and proof exports." }
  ],
  "paths": {
    "/submit-consent": {
      "post": {
        "tags": ["Consent"],
        "summary": "Submit a new SMS opt-in consent record",
        "description": "Called by the OptInFix embed when a user opts in. Produces a SHA-256 sealed audit record.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["brand_id", "phone", "disclosure_text"],
                "properties": {
                  "brand_id": { "type": "string", "format": "uuid" },
                  "phone": { "type": "string", "example": "+15551234567" },
                  "email": { "type": "string", "format": "email" },
                  "name": { "type": "string" },
                  "disclosure_text": { "type": "string" },
                  "extra_fields": { "type": "object", "additionalProperties": true }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Consent record created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "consent_id": { "type": "string", "format": "uuid" },
                    "hash": { "type": "string", "description": "SHA-256 hash sealing the record." },
                    "verify_url": { "type": "string", "format": "uri" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/verify-consent": {
      "get": {
        "tags": ["Consent"],
        "summary": "Verify a consent record by ID and hash",
        "parameters": [
          { "name": "id", "in": "query", "required": true, "schema": { "type": "string", "format": "uuid" } },
          { "name": "hash", "in": "query", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Verification result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "valid": { "type": "boolean" },
                    "captured_at": { "type": "string", "format": "date-time" },
                    "disclosure_text": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/update-consent-status": {
      "post": {
        "tags": ["Consent"],
        "summary": "Update the lifecycle status of a consent record",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["consent_id", "status"],
                "properties": {
                  "consent_id": { "type": "string", "format": "uuid" },
                  "status": {
                    "type": "string",
                    "enum": ["active", "revoked", "opted_out", "expired", "blacklisted"]
                  }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Status updated" } }
      }
    },
    "/brand-snippet": {
      "get": {
        "tags": ["Brand"],
        "summary": "Fetch a brand's embed snippet (HTML/iframe)",
        "parameters": [
          { "name": "brand_id", "in": "query", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": {
          "200": {
            "description": "Embed snippet",
            "content": {
              "text/html": { "schema": { "type": "string" } }
            }
          }
        }
      }
    },
    "/export-suppression-list": {
      "get": {
        "tags": ["Suppression"],
        "summary": "Export a CSV of all non-Active phone numbers for a brand",
        "parameters": [
          { "name": "brand_id", "in": "query", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": {
          "200": {
            "description": "CSV export",
            "content": { "text/csv": { "schema": { "type": "string" } } }
          }
        }
      }
    },
    "/download-consent-proof": {
      "get": {
        "tags": ["Consent"],
        "summary": "Download a legal-grade PDF certificate of consent",
        "parameters": [
          { "name": "consent_id", "in": "query", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": {
          "200": {
            "description": "PDF file",
            "content": { "application/pdf": { "schema": { "type": "string", "format": "binary" } } }
          }
        }
      }
    }
  }
}
