{
  "openapi": "3.1.0",
  "info": {
    "title": "finstat",
    "version": "0.2.0"
  },
  "paths": {
    "/v1/documents": {
      "post": {
        "tags": ["documents"],
        "summary": "Submit",
        "operationId": "submit_v1_documents_post",
        "security": [
          {
            "CustomerKey": []
          }
        ],
        "parameters": [
          {
            "name": "cnpj",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 14,
              "maxLength": 14,
              "pattern": "^[A-Z0-9]{12}[0-9]{2}$",
              "title": "Cnpj"
            }
          },
          {
            "name": "period_end",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date",
              "title": "Period End"
            }
          },
          {
            "name": "entity",
            "in": "query",
            "required": false,
            "schema": {
              "enum": ["Individual", "Controladora", "Consolidado", "Combinado"],
              "type": "string",
              "default": "Individual",
              "title": "Entity"
            }
          },
          {
            "name": "idempotency-key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128,
              "default": "",
              "title": "Idempotency-Key"
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentStatus"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: chave ausente, inválida, revogada, expirada ou sem o escopo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "4XX": {
            "description": "Outro erro do cliente, no mesmo formato.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "500": {
            "description": "internal_error: repita com a mesma Idempotency-Key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "503": {
            "description": "capacity_busy: espere Retry-After e repita.",
            "headers": {
              "Retry-After": {
                "description": "Segundos até repetir.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "409": {
            "description": "version_conflict: Idempotency-Key já usada com outra entrada.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "413": {
            "description": "pdf_too_large ou body_too_large.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "422": {
            "description": "pdf_and_idempotency_key_required, invalid_pdf ou invalid_request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/pdf": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        }
      }
    },
    "/v1/documents/{job_id}": {
      "get": {
        "tags": ["documents"],
        "summary": "Status",
        "operationId": "status_v1_documents__job_id__get",
        "security": [
          {
            "CustomerKey": []
          }
        ],
        "parameters": [
          {
            "name": "job_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Job Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentStatus"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: chave ausente, inválida, revogada, expirada ou sem o escopo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "4XX": {
            "description": "Outro erro do cliente, no mesmo formato.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "500": {
            "description": "internal_error: repita com a mesma Idempotency-Key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "503": {
            "description": "capacity_busy: espere Retry-After e repita.",
            "headers": {
              "Retry-After": {
                "description": "Segundos até repetir.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "404": {
            "description": "not_found: documento inexistente ou de outra empresa.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/documents/{job_id}/result": {
      "get": {
        "tags": ["documents"],
        "summary": "Result",
        "operationId": "result_v1_documents__job_id__result_get",
        "security": [
          {
            "CustomerKey": []
          }
        ],
        "parameters": [
          {
            "name": "job_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Job Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/History"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: chave ausente, inválida, revogada, expirada ou sem o escopo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "4XX": {
            "description": "Outro erro do cliente, no mesmo formato.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "500": {
            "description": "internal_error: repita com a mesma Idempotency-Key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "503": {
            "description": "capacity_busy: espere Retry-After e repita.",
            "headers": {
              "Retry-After": {
                "description": "Segundos até repetir.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "404": {
            "description": "not_found: documento inexistente ou de outra empresa.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "409": {
            "description": "not_completed: resultado antes da liberação.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/history/{cnpj}": {
      "get": {
        "tags": ["documents"],
        "summary": "History",
        "operationId": "history_v1_history__cnpj__get",
        "security": [
          {
            "CustomerKey": []
          }
        ],
        "parameters": [
          {
            "name": "cnpj",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Cnpj"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/History"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: chave ausente, inválida, revogada, expirada ou sem o escopo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "4XX": {
            "description": "Outro erro do cliente, no mesmo formato.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "500": {
            "description": "internal_error: repita com a mesma Idempotency-Key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "503": {
            "description": "capacity_busy: espere Retry-After e repita.",
            "headers": {
              "Retry-After": {
                "description": "Segundos até repetir.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ApiError": {
        "properties": {
          "error": {
            "type": "string",
            "title": "Error"
          }
        },
        "type": "object",
        "required": ["error"],
        "title": "ApiError",
        "description": "Body of every /v1 error: a stable code that never echoes the request."
      },
      "DocumentStatus": {
        "properties": {
          "id": {
            "type": "string",
            "title": "Id"
          },
          "status": {
            "$ref": "#/components/schemas/JobStatus"
          },
          "reason": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Reason"
          },
          "pages": {
            "type": "integer",
            "title": "Pages"
          },
          "processing_seconds": {
            "type": "number",
            "title": "Processing Seconds"
          },
          "engine_version": {
            "type": "string",
            "title": "Engine Version",
            "default": ""
          },
          "model_version": {
            "type": "string",
            "title": "Model Version",
            "default": ""
          }
        },
        "type": "object",
        "required": ["id", "status", "reason", "pages", "processing_seconds"],
        "title": "DocumentStatus"
      },
      "History": {
        "additionalProperties": {
          "items": {
            "$ref": "#/components/schemas/HistoryEntry"
          },
          "type": "array"
        },
        "type": "object"
      },
      "HistoryEntry": {
        "properties": {
          "tempo": {
            "type": "string",
            "title": "Tempo",
            "default": ""
          },
          "conf": {
            "type": "number",
            "title": "Conf",
            "default": 1.0
          },
          "data": {
            "type": "string",
            "title": "Data"
          },
          "data_ano": {
            "type": "string",
            "title": "Data Ano"
          },
          "termo_total": {
            "type": "string",
            "title": "Termo Total"
          },
          "valor": {
            "type": "string",
            "title": "Valor"
          },
          "page": {
            "type": "integer",
            "title": "Page"
          },
          "id": {
            "type": "string",
            "title": "Id"
          },
          "subsection": {
            "type": "string",
            "title": "Subsection",
            "default": ""
          },
          "tipo": {
            "type": "string",
            "title": "Tipo"
          },
          "section": {
            "type": "string",
            "title": "Section"
          },
          "moeda": {
            "type": "string",
            "title": "Moeda",
            "default": "BRL"
          },
          "escala": {
            "type": "string",
            "title": "Escala",
            "default": "1"
          },
          "empresa": {
            "type": "string",
            "title": "Empresa"
          },
          "cnpj": {
            "type": "string",
            "title": "Cnpj"
          },
          "consolidado": {
            "type": "boolean",
            "title": "Consolidado"
          },
          "tipo_balanco": {
            "type": "string",
            "enum": ["Individual", "Controladora", "Consolidado", "Combinado"],
            "title": "Tipo Balanco"
          },
          "y": {
            "type": "number",
            "title": "Y"
          },
          "x": {
            "type": "number",
            "title": "X"
          },
          "unique_id": {
            "type": "string",
            "title": "Unique Id"
          },
          "parent": {
            "type": "string",
            "title": "Parent",
            "default": ""
          },
          "is_total": {
            "type": "integer",
            "title": "Is Total",
            "default": 0
          },
          "over_threshold_h": {
            "type": "integer",
            "title": "Over Threshold H",
            "default": 0
          },
          "over_threshold_v": {
            "type": "integer",
            "title": "Over Threshold V",
            "default": 0
          },
          "bbox_left": {
            "type": "number",
            "title": "Bbox Left"
          },
          "bbox_top": {
            "type": "number",
            "title": "Bbox Top"
          },
          "bbox_height": {
            "type": "number",
            "title": "Bbox Height"
          },
          "bbox_width": {
            "type": "number",
            "title": "Bbox Width"
          },
          "data_init": {
            "type": "string",
            "title": "Data Init",
            "default": ""
          },
          "formula": {
            "type": "string",
            "title": "Formula",
            "default": ""
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "data",
          "data_ano",
          "termo_total",
          "valor",
          "page",
          "id",
          "tipo",
          "section",
          "empresa",
          "cnpj",
          "consolidado",
          "tipo_balanco",
          "y",
          "x",
          "unique_id",
          "bbox_left",
          "bbox_top",
          "bbox_height",
          "bbox_width"
        ],
        "title": "HistoryEntry"
      },
      "JobStatus": {
        "type": "string",
        "enum": ["queued", "processing", "review", "completed", "rejected", "error"],
        "title": "JobStatus"
      }
    },
    "securitySchemes": {
      "CustomerKey": {
        "type": "http",
        "scheme": "bearer"
      }
    }
  }
}
