{
  "openapi": "3.1.0",
  "info": {
    "title": "Gym API",
    "version": "1.0.0",
    "description": "Hello World HTTP/JSON para web e futuro app nativo. Os exemplos de infraestrutura usam um token de smoke test, não autenticação de usuários."
  },
  "servers": [{ "url": "/api/v1" }],
  "paths": {
    "/hello": {
      "get": {
        "operationId": "getHello",
        "summary": "Hello World sem serviços externos",
        "security": [],
        "responses": {
          "200": { "$ref": "#/components/responses/Hello" }
        }
      }
    },
    "/hello/database": {
      "get": {
        "operationId": "getDatabaseHello",
        "summary": "Hello World via SELECT parametrizado no Neon",
        "security": [{ "DemoBearer": [] }],
        "responses": {
          "200": { "$ref": "#/components/responses/Hello" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "503": { "$ref": "#/components/responses/Unavailable" }
        }
      }
    },
    "/hello/queue": {
      "post": {
        "operationId": "enqueueHello",
        "summary": "Enfileira Hello World; sem body",
        "security": [{ "DemoBearer": [] }],
        "responses": {
          "202": {
            "description": "Mensagem aceita. A conclusão do consumidor é assíncrona. messageId pode ser null quando o provedor aceita a mensagem para processamento diferido.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/QueueAccepted" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "503": { "$ref": "#/components/responses/Unavailable" }
        }
      }
    },
    "/hello/workflow": {
      "post": {
        "operationId": "startHelloWorkflow",
        "summary": "Inicia Hello World durável; sem body",
        "security": [{ "DemoBearer": [] }],
        "responses": {
          "202": {
            "description": "Workflow iniciado. A execução é assíncrona.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/WorkflowAccepted" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "503": { "$ref": "#/components/responses/Unavailable" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "DemoBearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "DEMO_API_TOKEN: segredo exclusivo para smoke tests no servidor. Nunca distribuir no cliente."
      }
    },
    "responses": {
      "Hello": {
        "description": "Hello World",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Hello" },
            "example": { "data": { "message": "Hello World" } }
          }
        }
      },
      "Unauthorized": {
        "description": "Bearer token ausente ou inválido (UNAUTHORIZED).",
        "headers": {
          "WWW-Authenticate": { "schema": { "type": "string", "const": "Bearer" } }
        },
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "example": {
              "error": { "code": "UNAUTHORIZED", "message": "A valid bearer token is required." }
            }
          }
        }
      },
      "Unavailable": {
        "description": "Exemplo desabilitado/configuração ausente (NOT_CONFIGURED) ou provedor indisponível (SERVICE_UNAVAILABLE).",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "example": {
              "error": { "code": "NOT_CONFIGURED", "message": "Demo endpoints are disabled." }
            }
          }
        }
      }
    },
    "schemas": {
      "Hello": {
        "type": "object",
        "required": ["data"],
        "additionalProperties": false,
        "properties": {
          "data": {
            "type": "object",
            "required": ["message"],
            "additionalProperties": false,
            "properties": { "message": { "type": "string", "examples": ["Hello World"] } }
          }
        }
      },
      "QueueAccepted": {
        "type": "object",
        "required": ["data"],
        "additionalProperties": false,
        "properties": {
          "data": {
            "type": "object",
            "required": ["messageId"],
            "additionalProperties": false,
            "properties": { "messageId": { "type": ["string", "null"] } }
          }
        }
      },
      "WorkflowAccepted": {
        "type": "object",
        "required": ["data"],
        "additionalProperties": false,
        "properties": {
          "data": {
            "type": "object",
            "required": ["runId"],
            "additionalProperties": false,
            "properties": { "runId": { "type": "string" } }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": ["error"],
        "additionalProperties": false,
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "additionalProperties": false,
            "properties": {
              "code": {
                "type": "string",
                "enum": ["UNAUTHORIZED", "NOT_CONFIGURED", "SERVICE_UNAVAILABLE"]
              },
              "message": { "type": "string" }
            }
          }
        }
      }
    }
  }
}
