{
  "openapi": "3.0.3",
  "info": {
    "title": "RPA DEC Porto Alegre — Contrato via PES2B Agent",
    "version": "1.0.0",
    "description": "A DEC POA não expõe API própria. Este contrato documenta sua execução assíncrona pelo PES2B Agent."
  },
  "servers": [
    {
      "url": "http://127.0.0.1:3000",
      "description": "PES2B Agent local"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-PES2B-API-KEY"
      }
    },
    "schemas": {
      "Empresa": {
        "type": "object",
        "required": [
          "razaoSocial",
          "cnpj",
          "senha",
          "inscricaoMunicipal",
          "competenciaAno",
          "competenciaMes"
        ],
        "properties": {
          "razaoSocial": {
            "type": "string"
          },
          "cnpj": {
            "type": "string"
          },
          "senha": {
            "type": "string",
            "format": "password"
          },
          "inscricaoMunicipal": {
            "type": "string"
          },
          "competenciaAno": {
            "type": "string"
          },
          "competenciaMes": {
            "type": "string"
          }
        }
      },
      "RunRequest": {
        "type": "object",
        "properties": {
          "requestId": {
            "type": "string"
          },
          "input": {
            "type": "object",
            "properties": {
              "empresas": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Empresa"
                }
              },
              "headless": {
                "type": "boolean",
                "default": false
              },
              "slowMo": {
                "type": "integer",
                "default": 300
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/automations/dec-poa/run": {
      "post": {
        "summary": "Executar DEC POA",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RunRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Job criado"
          }
        }
      }
    },
    "/api/v1/jobs/{jobId}": {
      "get": {
        "summary": "Consultar resultado",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Job"
          }
        }
      }
    },
    "/api/v1/jobs/{jobId}/files": {
      "get": {
        "summary": "Listar PDFs gerados",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Arquivos"
          }
        }
      }
    }
  }
}