{
  "openapi": "3.1.0",
  "info": {
    "title": "GPTCTEAM Ops Gateway API",
    "version": "1.0.0",
    "summary": "Authenticated Netlify functions for operational workflows.",
    "description": "Use the `X-Ops-Api-Key` header to call gateway functions for GitHub, Netlify, Supabase, email provider, and Discord operations."
  },
  "servers": [
    {
      "url": "/api/v1",
      "description": "Current production API base"
    }
  ],
  "tags": [
    { "name": "GitHub", "description": "Repository, workflow, log, and artifact helpers." },
    { "name": "Netlify", "description": "Deployment and environment-variable operations." },
    { "name": "Supabase", "description": "Read-only database inspection helpers." },
    { "name": "Email", "description": "Resend and SMTP2GO inspection helpers." },
    { "name": "Discord", "description": "Send a message through the configured Discord webhook." }
  ],
  "security": [
    {
      "OpsApiKey": []
    }
  ],
  "paths": {
    "/github-branches": {
      "get": {
        "tags": ["GitHub"],
        "summary": "List repository branches",
        "operationId": "listGithubBranches",
        "parameters": [
          { "$ref": "#/components/parameters/Page" },
          { "$ref": "#/components/parameters/PerPage100" },
          {
            "name": "protected",
            "in": "query",
            "schema": { "type": "string", "enum": ["true", "false"] },
            "description": "Optional GitHub protected branch filter."
          }
        ],
        "responses": {
          "200": { "description": "Branches returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GithubBranchesResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "405": { "$ref": "#/components/responses/MethodNotAllowed" }
        }
      }
    },
    "/github-issues": {
      "get": {
        "tags": ["GitHub"],
        "summary": "List repository issues",
        "operationId": "listGithubIssues",
        "parameters": [
          { "$ref": "#/components/parameters/Page" },
          { "$ref": "#/components/parameters/PerPage50" },
          { "name": "state", "in": "query", "schema": { "type": "string", "default": "open", "enum": ["open", "closed", "all"] } },
          { "name": "labels", "in": "query", "schema": { "type": "string" }, "description": "Comma-separated GitHub labels." },
          { "name": "assignee", "in": "query", "schema": { "type": "string" } },
          { "name": "since", "in": "query", "schema": { "type": "string", "format": "date-time" } },
          { "name": "sort", "in": "query", "schema": { "type": "string", "default": "updated", "enum": ["created", "updated", "comments"] } },
          { "$ref": "#/components/parameters/SortDirection" }
        ],
        "responses": {
          "200": { "description": "Issues returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GithubIssuesResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/github-pulls": {
      "get": {
        "tags": ["GitHub"],
        "summary": "List repository pull requests",
        "operationId": "listGithubPulls",
        "parameters": [
          { "$ref": "#/components/parameters/Page" },
          { "$ref": "#/components/parameters/PerPage50" },
          { "name": "state", "in": "query", "schema": { "type": "string", "default": "open", "enum": ["open", "closed", "all"] } },
          { "name": "head", "in": "query", "schema": { "type": "string" } },
          { "name": "base", "in": "query", "schema": { "type": "string" } },
          { "name": "sort", "in": "query", "schema": { "type": "string", "default": "updated", "enum": ["created", "updated", "popularity", "long-running"] } },
          { "$ref": "#/components/parameters/SortDirection" }
        ],
        "responses": {
          "200": { "description": "Pull requests returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GithubPullsResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/github-workflows": {
      "get": {
        "tags": ["GitHub"],
        "summary": "List GitHub Actions workflows",
        "operationId": "listGithubWorkflows",
        "parameters": [
          { "$ref": "#/components/parameters/Page" },
          { "$ref": "#/components/parameters/PerPage100" }
        ],
        "responses": {
          "200": { "description": "Workflows returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GithubWorkflowsResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/github-workflow-runs": {
      "get": {
        "tags": ["GitHub"],
        "summary": "List GitHub Actions workflow runs",
        "operationId": "listGithubWorkflowRuns",
        "parameters": [
          { "$ref": "#/components/parameters/Page" },
          { "$ref": "#/components/parameters/PerPage50" },
          { "name": "branch", "in": "query", "schema": { "type": "string" } },
          { "name": "status", "in": "query", "schema": { "type": "string" }, "description": "Accepts GitHub statuses and aliases such as failed, passed, running, or canceled." },
          { "name": "event", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Workflow runs returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GithubWorkflowRunsResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/github-workflow-run-artifacts": {
      "get": {
        "tags": ["GitHub"],
        "summary": "List artifacts for a workflow run",
        "operationId": "listGithubWorkflowRunArtifacts",
        "parameters": [
          { "$ref": "#/components/parameters/RunId" },
          { "$ref": "#/components/parameters/Page" },
          { "$ref": "#/components/parameters/PerPage50" }
        ],
        "responses": {
          "200": { "description": "Artifacts returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GithubRunArtifactsResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/github-workflow-run-logs": {
      "get": {
        "tags": ["GitHub"],
        "summary": "List workflow run log files with excerpts",
        "operationId": "listGithubWorkflowRunLogs",
        "parameters": [
          { "$ref": "#/components/parameters/RunId" },
          { "name": "max_bytes_per_file", "in": "query", "schema": { "type": "integer", "default": 4000, "minimum": 500, "maximum": 20000 } }
        ],
        "responses": {
          "200": { "description": "Log files returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GithubLogFilesResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/github-workflow-run-log": {
      "get": {
        "tags": ["GitHub"],
        "summary": "Read one workflow run log file",
        "operationId": "getGithubWorkflowRunLog",
        "parameters": [
          { "$ref": "#/components/parameters/RunId" },
          { "$ref": "#/components/parameters/FilePath" },
          { "name": "max_bytes", "in": "query", "schema": { "type": "integer", "default": 50000, "minimum": 1000, "maximum": 200000 } },
          { "$ref": "#/components/parameters/StartLine" },
          { "$ref": "#/components/parameters/EndLine" }
        ],
        "responses": {
          "200": { "description": "Log file returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/TextFileResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/github-contents": {
      "get": {
        "tags": ["GitHub"],
        "summary": "List repository contents",
        "operationId": "listGithubContents",
        "parameters": [
          { "$ref": "#/components/parameters/RepoPathOptional" },
          { "$ref": "#/components/parameters/Ref" }
        ],
        "responses": {
          "200": { "description": "Repository contents returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GithubContentsResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/github-file": {
      "get": {
        "tags": ["GitHub"],
        "summary": "Read a text file from the repository",
        "operationId": "getGithubFile",
        "parameters": [
          { "$ref": "#/components/parameters/RepoPathRequired" },
          { "$ref": "#/components/parameters/Ref" },
          { "name": "max_bytes", "in": "query", "schema": { "type": "integer", "default": 50000, "minimum": 1000, "maximum": 200000 } },
          { "$ref": "#/components/parameters/StartLine" },
          { "$ref": "#/components/parameters/EndLine" }
        ],
        "responses": {
          "200": { "description": "File returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/TextFileResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "415": { "description": "Unsupported binary or unavailable file content.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/github-artifact-files": {
      "get": {
        "tags": ["GitHub"],
        "summary": "List files in a workflow artifact zip",
        "operationId": "listGithubArtifactFiles",
        "parameters": [
          { "$ref": "#/components/parameters/ArtifactId" },
          { "name": "max_bytes_per_file", "in": "query", "schema": { "type": "integer", "default": 4000, "minimum": 500, "maximum": 20000 } },
          { "name": "include_excerpts", "in": "query", "schema": { "type": "string", "default": "true", "enum": ["true", "false"] } },
          { "name": "path_contains", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Artifact files returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GithubArtifactFilesResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/github-artifact-file": {
      "get": {
        "tags": ["GitHub"],
        "summary": "Read one file from a workflow artifact zip",
        "operationId": "getGithubArtifactFile",
        "parameters": [
          { "$ref": "#/components/parameters/ArtifactId" },
          { "$ref": "#/components/parameters/FilePath" },
          { "name": "max_bytes", "in": "query", "schema": { "type": "integer", "default": 50000, "minimum": 1000, "maximum": 1000000 } },
          { "name": "return_base64", "in": "query", "schema": { "type": "string", "default": "false", "enum": ["true", "false"] } },
          { "$ref": "#/components/parameters/StartLine" },
          { "$ref": "#/components/parameters/EndLine" }
        ],
        "responses": {
          "200": { "description": "Artifact file returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ArtifactFileResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/netlify-deployments": {
      "get": {
        "tags": ["Netlify"],
        "summary": "List Netlify deployments",
        "operationId": "listNetlifyDeployments",
        "parameters": [
          { "$ref": "#/components/parameters/NetlifyTargetAll" },
          { "$ref": "#/components/parameters/Page" },
          { "$ref": "#/components/parameters/PerPage100" }
        ],
        "responses": {
          "200": { "description": "Deployments returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NetlifyDeploymentsResponse" } } } },
          "207": { "description": "Partial success when one target fails.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NetlifyDeploymentsResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/netlify-cancel-deployment": {
      "post": {
        "tags": ["Netlify"],
        "summary": "Cancel a Netlify deployment",
        "operationId": "cancelNetlifyDeployment",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/CancelDeploymentRequest" }
            }
          }
        },
        "responses": {
          "200": { "description": "Cancellation requested.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/MessageResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/netlify-delete-deployment": {
      "post": {
        "tags": ["Netlify"],
        "summary": "Delete a Netlify deployment",
        "operationId": "deleteNetlifyDeployment",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/DeleteDeploymentRequest" }
            }
          }
        },
        "responses": {
          "200": { "description": "Deployment deleted.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/MessageResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "403": { "description": "Production delete confirmation missing.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/netlify-env-vars": {
      "get": {
        "tags": ["Netlify"],
        "summary": "List Netlify environment variables",
        "operationId": "listNetlifyEnvVars",
        "parameters": [
          { "$ref": "#/components/parameters/NetlifyTarget" },
          { "$ref": "#/components/parameters/SiteId" },
          { "$ref": "#/components/parameters/NetlifyContextAll" },
          { "$ref": "#/components/parameters/ContextParameter" },
          { "name": "reveal_values", "in": "query", "schema": { "type": "string", "default": "false", "enum": ["true", "false"] } }
        ],
        "responses": {
          "200": { "description": "Environment variables returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/EnvVarsResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/netlify-env-var": {
      "get": {
        "tags": ["Netlify"],
        "summary": "Get one Netlify environment variable",
        "operationId": "getNetlifyEnvVar",
        "parameters": [
          { "$ref": "#/components/parameters/NetlifyTarget" },
          { "$ref": "#/components/parameters/SiteId" },
          { "name": "key", "in": "query", "required": true, "schema": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" } },
          { "$ref": "#/components/parameters/NetlifyContextAll" },
          { "$ref": "#/components/parameters/ContextParameter" },
          { "name": "reveal_value", "in": "query", "schema": { "type": "string", "default": "false", "enum": ["true", "false"] } }
        ],
        "responses": {
          "200": { "description": "Environment variable returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/EnvVarResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      },
      "post": {
        "tags": ["Netlify"],
        "summary": "Create or update one Netlify environment variable",
        "operationId": "setNetlifyEnvVar",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/SetEnvVarRequest" }
            }
          }
        },
        "responses": {
          "200": { "description": "Environment variable created or updated.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/MessageResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/supabase-tables": {
      "get": {
        "tags": ["Supabase"],
        "summary": "List database tables",
        "operationId": "listSupabaseTables",
        "parameters": [
          { "$ref": "#/components/parameters/SupabaseTarget" },
          { "$ref": "#/components/parameters/SupabaseSchemaAll" }
        ],
        "responses": {
          "200": { "description": "Tables returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SupabaseTablesResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/supabase-columns": {
      "get": {
        "tags": ["Supabase"],
        "summary": "List columns for a database table",
        "operationId": "listSupabaseColumns",
        "parameters": [
          { "$ref": "#/components/parameters/SupabaseTarget" },
          { "$ref": "#/components/parameters/SupabaseSchema" },
          { "name": "table", "in": "query", "required": true, "schema": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" } }
        ],
        "responses": {
          "200": { "description": "Columns returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SupabaseColumnsResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/supabase-read-rows": {
      "post": {
        "tags": ["Supabase"],
        "summary": "Read table rows with safe filters",
        "operationId": "readSupabaseRows",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ReadRowsRequest" }
            }
          }
        },
        "responses": {
          "200": { "description": "Rows returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ReadRowsResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "403": { "description": "Sensitive auth column refused.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "404": { "$ref": "#/components/responses/NotFound" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/resend-emails": {
      "get": {
        "tags": ["Email"],
        "summary": "List recent Resend emails",
        "operationId": "listResendEmails",
        "parameters": [
          { "$ref": "#/components/parameters/Limit100" },
          { "$ref": "#/components/parameters/FromFilter" },
          { "$ref": "#/components/parameters/ToFilter" },
          { "$ref": "#/components/parameters/SubjectContains" },
          { "name": "status", "in": "query", "schema": { "type": "string" } },
          { "name": "last_event", "in": "query", "schema": { "type": "string" } },
          { "$ref": "#/components/parameters/CreatedAfter" },
          { "$ref": "#/components/parameters/CreatedBefore" }
        ],
        "responses": {
          "200": { "description": "Emails returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/EmailsResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/resend-email": {
      "get": {
        "tags": ["Email"],
        "summary": "Get one Resend email",
        "operationId": "getResendEmail",
        "parameters": [
          { "$ref": "#/components/parameters/EmailId" }
        ],
        "responses": {
          "200": { "description": "Email returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/EmailDetail" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/smtp2go-emails": {
      "get": {
        "tags": ["Email"],
        "summary": "List recent SMTP2GO email activity",
        "operationId": "listSmtp2goEmails",
        "parameters": [
          { "$ref": "#/components/parameters/Page" },
          { "$ref": "#/components/parameters/Limit100" },
          { "$ref": "#/components/parameters/FromFilter" },
          { "$ref": "#/components/parameters/ToFilter" },
          { "$ref": "#/components/parameters/SubjectContains" },
          { "name": "status", "in": "query", "schema": { "type": "string" } },
          { "name": "event", "in": "query", "schema": { "type": "string" } },
          { "$ref": "#/components/parameters/CreatedAfter" },
          { "$ref": "#/components/parameters/CreatedBefore" }
        ],
        "responses": {
          "200": { "description": "Email activity returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/EmailsResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/smtp2go-email": {
      "get": {
        "tags": ["Email"],
        "summary": "Get one SMTP2GO email activity item",
        "operationId": "getSmtp2goEmail",
        "parameters": [
          { "$ref": "#/components/parameters/EmailId" }
        ],
        "responses": {
          "200": { "description": "Email activity returned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/EmailDetail" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/discord-message": {
      "post": {
        "tags": ["Discord"],
        "summary": "Send a Discord webhook message",
        "operationId": "sendDiscordMessage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/DiscordMessageRequest" }
            }
          }
        },
        "responses": {
          "200": { "description": "Message sent.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/MessageResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "OpsApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Ops-Api-Key",
        "description": "Shared gateway key from OPS_API_KEY."
      }
    },
    "parameters": {
      "Page": { "name": "page", "in": "query", "schema": { "type": "integer", "default": 1, "minimum": 1, "maximum": 1000 } },
      "PerPage50": { "name": "per_page", "in": "query", "schema": { "type": "integer", "default": 50, "minimum": 1, "maximum": 100 } },
      "PerPage100": { "name": "per_page", "in": "query", "schema": { "type": "integer", "default": 100, "minimum": 1, "maximum": 100 } },
      "Limit100": { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 25, "minimum": 1, "maximum": 100 } },
      "SortDirection": { "name": "direction", "in": "query", "schema": { "type": "string", "default": "desc", "enum": ["asc", "desc"] } },
      "RunId": { "name": "run_id", "in": "query", "required": true, "schema": { "type": "string", "pattern": "^[0-9]+$" } },
      "ArtifactId": { "name": "artifact_id", "in": "query", "required": true, "schema": { "type": "string", "pattern": "^[0-9]+$" } },
      "FilePath": { "name": "path", "in": "query", "required": true, "schema": { "type": "string" } },
      "RepoPathOptional": { "name": "path", "in": "query", "schema": { "type": "string", "default": "" } },
      "RepoPathRequired": { "name": "path", "in": "query", "required": true, "schema": { "type": "string" } },
      "Ref": { "name": "ref", "in": "query", "schema": { "type": "string", "default": "dev" } },
      "StartLine": { "name": "start_line", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 1000000 } },
      "EndLine": { "name": "end_line", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 1000000 } },
      "NetlifyTarget": { "name": "target", "in": "query", "schema": { "$ref": "#/components/schemas/NetlifyTarget" } },
      "NetlifyTargetAll": { "name": "target", "in": "query", "schema": { "type": "string", "default": "gptcteam", "enum": ["gptcteam", "cteam", "all"] } },
      "SiteId": { "name": "site_id", "in": "query", "schema": { "type": "string" }, "description": "Optional override for the target's configured site id." },
      "NetlifyContextAll": { "name": "context", "in": "query", "schema": { "$ref": "#/components/schemas/NetlifyContextAll" } },
      "ContextParameter": { "name": "context_parameter", "in": "query", "schema": { "type": "string" } },
      "SupabaseTarget": { "name": "target", "in": "query", "schema": { "$ref": "#/components/schemas/SupabaseTarget" } },
      "SupabaseSchema": { "name": "schema", "in": "query", "schema": { "type": "string", "default": "public", "enum": ["public", "auth"] } },
      "SupabaseSchemaAll": { "name": "schema", "in": "query", "schema": { "type": "string", "default": "all", "enum": ["public", "auth", "all"] } },
      "FromFilter": { "name": "from", "in": "query", "schema": { "type": "string" } },
      "ToFilter": { "name": "to", "in": "query", "schema": { "type": "string" } },
      "SubjectContains": { "name": "subject_contains", "in": "query", "schema": { "type": "string" } },
      "CreatedAfter": { "name": "created_after", "in": "query", "schema": { "type": "string", "format": "date-time" } },
      "CreatedBefore": { "name": "created_before", "in": "query", "schema": { "type": "string", "format": "date-time" } },
      "EmailId": { "name": "id", "in": "query", "required": true, "schema": { "type": "string" } }
    },
    "responses": {
      "BadRequest": { "description": "Invalid request.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Unauthorized": { "description": "Missing or invalid X-Ops-Api-Key.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "NotFound": { "description": "Resource not found.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "MethodNotAllowed": { "description": "Unsupported HTTP method.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "message": { "type": "string" },
          "status": { "type": "integer" },
          "error": {}
        },
        "required": ["message"],
        "additionalProperties": true
      },
      "MessageResponse": {
        "type": "object",
        "properties": {
          "message": { "type": "string" }
        },
        "required": ["message"],
        "additionalProperties": true
      },
      "NetlifyTarget": {
        "type": "string",
        "default": "gptcteam",
        "enum": ["gptcteam", "cteam"]
      },
      "NetlifyContextAll": {
        "type": "string",
        "default": "all",
        "enum": ["all", "production", "deploy-preview", "branch-deploy", "dev"]
      },
      "SupabaseTarget": {
        "type": "string",
        "default": "feature-kev",
        "enum": ["prod", "dev", "feature-kev", "feature-fern", "test-kev", "test-fern"]
      },
      "GithubRepoEnvelope": {
        "type": "object",
        "properties": {
          "owner": { "type": "string" },
          "repo": { "type": "string" },
          "page": { "type": "integer" },
          "per_page": { "type": "integer" },
          "count": { "type": "integer" }
        },
        "additionalProperties": true
      },
      "GithubBranchesResponse": {
        "allOf": [
          { "$ref": "#/components/schemas/GithubRepoEnvelope" },
          {
            "type": "object",
            "properties": {
              "branches": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "name": { "type": "string" },
                    "protected": { "type": "boolean" },
                    "commit_sha": { "type": "string" },
                    "commit_url": { "type": "string" }
                  }
                }
              }
            }
          }
        ]
      },
      "GithubIssuesResponse": {
        "allOf": [
          { "$ref": "#/components/schemas/GithubRepoEnvelope" },
          {
            "type": "object",
            "properties": {
              "state": { "type": "string" },
              "issues": {
                "type": "array",
                "items": { "$ref": "#/components/schemas/GithubIssue" }
              }
            }
          }
        ]
      },
      "GithubIssue": {
        "type": "object",
        "properties": {
          "number": { "type": "integer" },
          "title": { "type": "string" },
          "state": { "type": "string" },
          "html_url": { "type": "string" },
          "user": { "type": "string" },
          "labels": { "type": "array", "items": { "type": "string" } },
          "assignees": { "type": "array", "items": { "type": "string" } },
          "comments": { "type": "integer" },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" },
          "closed_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "GithubPullsResponse": {
        "allOf": [
          { "$ref": "#/components/schemas/GithubRepoEnvelope" },
          {
            "type": "object",
            "properties": {
              "state": { "type": "string" },
              "pulls": {
                "type": "array",
                "items": { "$ref": "#/components/schemas/GithubPull" }
              }
            }
          }
        ]
      },
      "GithubPull": {
        "type": "object",
        "properties": {
          "number": { "type": "integer" },
          "title": { "type": "string" },
          "state": { "type": "string" },
          "draft": { "type": "boolean" },
          "html_url": { "type": "string" },
          "user": { "type": "string" },
          "head_ref": { "type": "string" },
          "head_sha": { "type": "string" },
          "base_ref": { "type": "string" },
          "mergeable_state": { "type": ["string", "null"] },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" },
          "closed_at": { "type": ["string", "null"], "format": "date-time" },
          "merged_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "GithubWorkflowsResponse": {
        "allOf": [
          { "$ref": "#/components/schemas/GithubRepoEnvelope" },
          {
            "type": "object",
            "properties": {
              "total_count": { "type": "integer" },
              "workflows": { "type": "array", "items": { "$ref": "#/components/schemas/GithubWorkflow" } }
            }
          }
        ]
      },
      "GithubWorkflow": {
        "type": "object",
        "properties": {
          "id": { "type": "integer" },
          "name": { "type": "string" },
          "path": { "type": "string" },
          "state": { "type": "string" },
          "html_url": { "type": "string" },
          "badge_url": { "type": "string" },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" }
        }
      },
      "GithubWorkflowRunsResponse": {
        "allOf": [
          { "$ref": "#/components/schemas/GithubRepoEnvelope" },
          {
            "type": "object",
            "properties": {
              "total_count": { "type": "integer" },
              "runs": { "type": "array", "items": { "$ref": "#/components/schemas/GithubWorkflowRun" } }
            }
          }
        ]
      },
      "GithubWorkflowRun": {
        "type": "object",
        "properties": {
          "id": { "type": "integer" },
          "name": { "type": "string" },
          "display_title": { "type": "string" },
          "workflow_id": { "type": "integer" },
          "workflow_url": { "type": "string" },
          "html_url": { "type": "string" },
          "status": { "type": "string" },
          "conclusion": { "type": ["string", "null"] },
          "event": { "type": "string" },
          "branch": { "type": "string" },
          "head_sha": { "type": "string" },
          "actor": { "type": "string" },
          "run_number": { "type": "integer" },
          "run_attempt": { "type": "integer" },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" },
          "run_started_at": { "type": "string", "format": "date-time" }
        }
      },
      "GithubRunArtifactsResponse": {
        "allOf": [
          { "$ref": "#/components/schemas/GithubRepoEnvelope" },
          {
            "type": "object",
            "properties": {
              "run_id": { "type": "string" },
              "total_count": { "type": "integer" },
              "artifacts": { "type": "array", "items": { "$ref": "#/components/schemas/GithubArtifact" } }
            }
          }
        ]
      },
      "GithubArtifact": {
        "type": "object",
        "properties": {
          "id": { "type": "integer" },
          "name": { "type": "string" },
          "size_in_bytes": { "type": "integer" },
          "expired": { "type": "boolean" },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" },
          "expires_at": { "type": "string", "format": "date-time" },
          "archive_download_url": { "type": "string" }
        }
      },
      "GithubLogFilesResponse": {
        "allOf": [
          { "$ref": "#/components/schemas/GithubRepoEnvelope" },
          {
            "type": "object",
            "properties": {
              "run_id": { "type": "string" },
              "max_bytes_per_file": { "type": "integer" },
              "files": { "type": "array", "items": { "$ref": "#/components/schemas/TextFileSummary" } }
            }
          }
        ]
      },
      "GithubContentsResponse": {
        "type": "object",
        "properties": {
          "owner": { "type": "string" },
          "repo": { "type": "string" },
          "ref": { "type": "string" },
          "path": { "type": "string" },
          "type": { "type": "string", "enum": ["directory", "file", "symlink", "submodule"] },
          "count": { "type": "integer" },
          "entries": { "type": "array", "items": { "$ref": "#/components/schemas/GithubContentEntry" } },
          "entry": { "$ref": "#/components/schemas/GithubContentEntry" }
        },
        "additionalProperties": true
      },
      "GithubContentEntry": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "path": { "type": "string" },
          "type": { "type": "string" },
          "size": { "type": "integer" },
          "sha": { "type": "string" },
          "html_url": { "type": "string" },
          "download_url": { "type": ["string", "null"] }
        }
      },
      "TextFileSummary": {
        "type": "object",
        "properties": {
          "path": { "type": "string" },
          "size": { "type": "integer" },
          "compressed_size": { "type": "integer" },
          "excerpt": { "type": "string" },
          "excerpt_truncated": { "type": "boolean" },
          "returned_bytes": { "type": "integer" },
          "mime_type": { "type": "string" },
          "is_text": { "type": "boolean" },
          "is_image": { "type": "boolean" }
        },
        "additionalProperties": true
      },
      "TextFileResponse": {
        "type": "object",
        "properties": {
          "owner": { "type": "string" },
          "repo": { "type": "string" },
          "ref": { "type": "string" },
          "run_id": { "type": "string" },
          "path": { "type": "string" },
          "name": { "type": "string" },
          "sha": { "type": "string" },
          "size": { "type": "integer" },
          "returned_bytes": { "type": "integer" },
          "max_bytes": { "type": "integer" },
          "truncated": { "type": "boolean" },
          "returned_start_line": { "type": "integer" },
          "returned_end_line": { "type": "integer" },
          "total_lines": { "type": "integer" },
          "line_sliced": { "type": "boolean" },
          "html_url": { "type": "string" },
          "download_url": { "type": ["string", "null"] },
          "content": { "type": "string" }
        },
        "additionalProperties": true
      },
      "GithubArtifactFilesResponse": {
        "allOf": [
          { "$ref": "#/components/schemas/GithubRepoEnvelope" },
          {
            "type": "object",
            "properties": {
              "artifact_id": { "type": "string" },
              "max_bytes_per_file": { "type": "integer" },
              "include_excerpts": { "type": "boolean" },
              "path_contains": { "type": "string" },
              "files": { "type": "array", "items": { "$ref": "#/components/schemas/TextFileSummary" } }
            }
          }
        ]
      },
      "ArtifactFileResponse": {
        "allOf": [
          { "$ref": "#/components/schemas/TextFileResponse" },
          {
            "type": "object",
            "properties": {
              "artifact_id": { "type": "string" },
              "mime_type": { "type": "string" },
              "is_text": { "type": "boolean" },
              "is_image": { "type": "boolean" },
              "base64": { "type": "string" },
              "data_url": { "type": "string" }
            }
          }
        ]
      },
      "NetlifyDeploymentsResponse": {
        "type": "object",
        "properties": {
          "target": { "type": "string" },
          "page": { "type": "integer" },
          "per_page": { "type": "integer" },
          "count": { "type": "integer" },
          "deployments": { "type": "array", "items": { "$ref": "#/components/schemas/NetlifyDeployment" } },
          "errors": { "type": "array", "items": { "type": "object", "additionalProperties": true } }
        }
      },
      "NetlifyDeployment": {
        "type": "object",
        "properties": {
          "project": { "type": "string" },
          "id": { "type": "string" },
          "site_id": { "type": "string" },
          "site_name": { "type": "string" },
          "name": { "type": "string" },
          "deploy_url": { "type": "string" },
          "url": { "type": "string" },
          "admin_url": { "type": "string" },
          "branch": { "type": "string" },
          "context": { "type": "string" },
          "state": { "type": "string" },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" },
          "published_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "CancelDeploymentRequest": {
        "type": "object",
        "required": ["target", "deploy_id"],
        "properties": {
          "target": { "$ref": "#/components/schemas/NetlifyTarget" },
          "deploy_id": { "type": "string" }
        }
      },
      "DeleteDeploymentRequest": {
        "type": "object",
        "required": ["target", "deploy_id", "confirm_delete"],
        "properties": {
          "target": { "$ref": "#/components/schemas/NetlifyTarget" },
          "deploy_id": { "type": "string" },
          "confirm_delete": { "type": "boolean", "const": true },
          "production_confirmation": { "type": "string", "description": "Required for production deployments.", "example": "DELETE PRODUCTION DEPLOYMENT" }
        }
      },
      "EnvVarsResponse": {
        "type": "object",
        "properties": {
          "target": { "type": "string" },
          "project": { "type": "string" },
          "site_id": { "type": "string" },
          "context": { "type": "string" },
          "context_parameter": { "type": "string" },
          "reveal_values": { "type": "boolean" },
          "count": { "type": "integer" },
          "env_vars": { "type": "array", "items": { "$ref": "#/components/schemas/EnvVar" } }
        }
      },
      "EnvVarResponse": {
        "type": "object",
        "properties": {
          "target": { "type": "string" },
          "project": { "type": "string" },
          "site_id": { "type": "string" },
          "context": { "type": "string" },
          "context_parameter": { "type": "string" },
          "reveal_value": { "type": "boolean" },
          "env_var": { "$ref": "#/components/schemas/EnvVar" }
        }
      },
      "EnvVar": {
        "type": "object",
        "properties": {
          "key": { "type": "string" },
          "scopes": { "type": "array", "items": { "type": "string" } },
          "values": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "context": { "type": "string" },
                "context_parameter": { "type": "string" },
                "value": {}
              }
            }
          }
        }
      },
      "SetEnvVarRequest": {
        "type": "object",
        "required": ["key", "value", "confirm_set"],
        "properties": {
          "target": { "$ref": "#/components/schemas/NetlifyTarget" },
          "site_id": { "type": "string" },
          "key": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" },
          "value": { "type": "string" },
          "context": { "$ref": "#/components/schemas/NetlifyContextAll" },
          "context_parameter": { "type": "string" },
          "scopes": { "type": "array", "items": { "type": "string" }, "default": ["builds", "functions"] },
          "confirm_set": { "type": "boolean", "const": true },
          "reveal_value": { "type": "boolean", "default": false }
        }
      },
      "SupabaseTablesResponse": {
        "type": "object",
        "properties": {
          "target": { "type": "string" },
          "target_label": { "type": "string" },
          "schemas": { "type": "array", "items": { "type": "string" } },
          "count": { "type": "integer" },
          "tables": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "schema": { "type": "string" },
                "table": { "type": "string" },
                "type": { "type": "string" }
              }
            }
          }
        }
      },
      "SupabaseColumnsResponse": {
        "type": "object",
        "properties": {
          "target": { "type": "string" },
          "target_label": { "type": "string" },
          "schema": { "type": "string" },
          "table": { "type": "string" },
          "count": { "type": "integer" },
          "columns": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": { "type": "string" },
                "data_type": { "type": "string" },
                "udt_name": { "type": "string" },
                "is_nullable": { "type": "string" },
                "column_default": { "type": ["string", "null"] },
                "sensitive": { "type": "boolean" }
              }
            }
          }
        }
      },
      "ReadRowsRequest": {
        "type": "object",
        "required": ["table"],
        "properties": {
          "target": { "$ref": "#/components/schemas/SupabaseTarget" },
          "schema": { "type": "string", "default": "public", "enum": ["public", "auth"] },
          "table": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" },
          "columns": { "type": "array", "items": { "type": "string" }, "default": ["*"] },
          "filters": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/ReadRowsFilter" }
          },
          "order_by": { "$ref": "#/components/schemas/ReadRowsOrder" },
          "limit": { "type": "integer", "default": 50, "minimum": 1, "maximum": 100 },
          "offset": { "type": "integer", "default": 0, "minimum": 0, "maximum": 10000 }
        }
      },
      "ReadRowsFilter": {
        "type": "object",
        "required": ["column"],
        "properties": {
          "column": { "type": "string" },
          "op": { "type": "string", "default": "eq", "enum": ["eq", "neq", "lt", "lte", "gt", "gte", "like", "ilike", "is_null", "not_null"] },
          "value": {}
        }
      },
      "ReadRowsOrder": {
        "type": "object",
        "required": ["column"],
        "properties": {
          "column": { "type": "string" },
          "direction": { "type": "string", "default": "asc", "enum": ["asc", "desc"] }
        }
      },
      "ReadRowsResponse": {
        "type": "object",
        "properties": {
          "target": { "type": "string" },
          "target_label": { "type": "string" },
          "schema": { "type": "string" },
          "table": { "type": "string" },
          "columns": { "type": "array", "items": { "type": "string" } },
          "limit": { "type": "integer" },
          "offset": { "type": "integer" },
          "count": { "type": "integer" },
          "rows": { "type": "array", "items": { "type": "object", "additionalProperties": true } }
        }
      },
      "EmailsResponse": {
        "type": "object",
        "properties": {
          "endpoint": { "type": "string" },
          "page": { "type": "integer" },
          "limit": { "type": "integer" },
          "count": { "type": "integer" },
          "emails": { "type": "array", "items": { "$ref": "#/components/schemas/EmailSummary" } },
          "raw_shape": { "type": "string" }
        },
        "additionalProperties": true
      },
      "EmailSummary": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "message_id": { "type": "string" },
          "from": { "type": "string" },
          "to": {},
          "cc": {},
          "bcc": {},
          "subject": { "type": "string" },
          "status": { "type": "string" },
          "event": { "type": "string" },
          "last_event": { "type": "string" },
          "created_at": { "type": "string" },
          "html_url": { "type": "string" }
        },
        "additionalProperties": true
      },
      "EmailDetail": {
        "allOf": [
          { "$ref": "#/components/schemas/EmailSummary" },
          {
            "type": "object",
            "properties": {
              "html": { "type": "string" },
              "text": { "type": "string" },
              "headers": {},
              "attachments": {},
              "raw": {}
            },
            "additionalProperties": true
          }
        ]
      },
      "DiscordMessageRequest": {
        "type": "object",
        "required": ["content"],
        "properties": {
          "content": { "type": "string", "minLength": 1, "maxLength": 1900 },
          "username": { "type": "string", "maxLength": 80 }
        }
      }
    }
  }
}
