{
 "openapi": "3.0.3",
 "info": {
  "title": "Genesis Débitos Veiculares",
  "version": "1.0.0",
  "description": "Consulta de débitos veiculares (Detran, Sefaz, Renainf) por placa e Renavam, no formato do spec v1.0 de 18/11/2026. Sandbox: client_id e client_secret = sandbox; o último dígito da placa escolhe o cenário (ver GET /v1/coverage)."
 },
 "servers": [
  {
   "url": "/"
  }
 ],
 "components": {
  "securitySchemes": {
   "oauth": {
    "type": "oauth2",
    "flows": {
     "clientCredentials": {
      "tokenUrl": "/v1/oauth/token",
      "scopes": {}
     }
    }
   }
  },
  "schemas": {
   "Erro": {
    "type": "object",
    "properties": {
     "status": {
      "type": "integer"
     },
     "errorCode": {
      "type": "string",
      "enum": [
       "VALIDATION_ERROR",
       "UNAUTHORIZED",
       "NOT_FOUND",
       "DUPLICATE_REQUEST",
       "STATE_NOT_SUPPORTED",
       "RATE_LIMITED",
       "SOURCE_UNAVAILABLE",
       "INTERNAL_ERROR"
      ]
     },
     "message": {
      "type": "string"
     },
     "traceId": {
      "type": "string"
     }
    }
   },
   "TipoDebito": {
    "type": "string",
    "enum": [
     "IPVA_UNIQUE",
     "IPVA_INSTALLMENT",
     "LICENSING",
     "INSURANCE",
     "TICKET",
     "RENAINF_TICKET",
     "SERVICES",
     "OTHER"
    ]
   },
   "Pedido": {
    "type": "object",
    "required": [
     "clientRequestId",
     "state",
     "licensePlate"
    ],
    "properties": {
     "clientRequestId": {
      "type": "string",
      "maxLength": 36
     },
     "state": {
      "type": "string",
      "minLength": 2,
      "maxLength": 2
     },
     "licensePlate": {
      "type": "string",
      "maxLength": 10,
      "example": "ABC1D23"
     },
     "renavam": {
      "type": "string",
      "maxLength": 11,
      "description": "Obrigatório em SC; dígito verificador conferido"
     },
     "documentNumber": {
      "type": "string",
      "maxLength": 14,
      "description": "CPF/CNPJ do dono, só números; exigido em algumas UFs (GET /v1/coverage)"
     },
     "includeTypes": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/TipoDebito"
      }
     }
    }
   },
   "Vehicle": {
    "type": "object",
    "properties": {
     "licensePlate": {
      "type": "string",
      "nullable": true
     },
     "renavam": {
      "type": "string",
      "nullable": true
     },
     "uf": {
      "type": "string",
      "nullable": true
     },
     "document": {
      "type": "string",
      "nullable": true
     },
     "model": {
      "type": "string",
      "nullable": true
     },
     "year": {
      "type": "string",
      "nullable": true
     },
     "color": {
      "type": "string",
      "nullable": true
     }
    }
   },
   "Debito": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "type": {
      "$ref": "#/components/schemas/TipoDebito"
     },
     "title": {
      "type": "string"
     },
     "description": {
      "type": "string"
     },
     "amount": {
      "type": "number"
     },
     "originalAmount": {
      "type": "number",
      "nullable": true
     },
     "discountAmount": {
      "type": "number",
      "nullable": true
     },
     "hasDiscount": {
      "type": "boolean"
     },
     "dueDate": {
      "type": "string",
      "format": "date"
     },
     "expirationDate": {
      "type": "string",
      "format": "date",
      "nullable": true
     },
     "isExpired": {
      "type": "boolean"
     },
     "year": {
      "type": "integer"
     },
     "required": {
      "type": "boolean"
     },
     "dependsOn": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "distinct": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "ticket": {
      "type": "object",
      "nullable": true,
      "properties": {
       "ait": {
        "type": "string"
       },
       "issuingAgency": {
        "type": "string"
       },
       "infractionDate": {
        "type": "string"
       },
       "infractionCode": {
        "type": "string"
       },
       "infractionDescription": {
        "type": "string"
       },
       "location": {
        "type": "string"
       },
       "situation": {
        "type": "string"
       }
      }
     }
    }
   },
   "Consulta": {
    "type": "object",
    "properties": {
     "idConsult": {
      "type": "string"
     },
     "clientRequestId": {
      "type": "string"
     },
     "status": {
      "type": "string",
      "enum": [
       "PROCESSING",
       "SUCCESS",
       "NOT_FOUND",
       "ERROR"
      ]
     },
     "vehicle": {
      "$ref": "#/components/schemas/Vehicle"
     },
     "debts": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Debito"
      }
     },
     "totalAmount": {
      "type": "number"
     },
     "consultedAt": {
      "type": "string",
      "format": "date-time"
     },
     "errorCode": {
      "type": "string"
     },
     "message": {
      "type": "string"
     },
     "retryable": {
      "type": "boolean"
     }
    }
   },
   "Evento": {
    "allOf": [
     {
      "$ref": "#/components/schemas/Consulta"
     },
     {
      "type": "object",
      "properties": {
       "eventId": {
        "type": "string"
       },
       "eventType": {
        "type": "string",
        "enum": [
         "DEBTS_FOUND",
         "NO_DEBTS",
         "VEHICLE_NOT_FOUND",
         "CONSULT_ERROR"
        ]
       }
      }
     }
    ],
    "description": "POST na URL cadastrada. Cabeçalhos: X-Event-Id (descarte duplicados) e X-Signature = sha256=HMAC-SHA256(secret, corpo). Até 5 tentativas (2, 4, 8, 16 s)."
   }
  }
 },
 "security": [
  {
   "oauth": []
  }
 ],
 "paths": {
  "/v1/oauth/token": {
   "post": {
    "summary": "Token OAuth 2.0 (client_credentials)",
    "security": [],
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "grant_type": {
          "type": "string"
         },
         "client_id": {
          "type": "string"
         },
         "client_secret": {
          "type": "string"
         }
        }
       }
      },
      "application/x-www-form-urlencoded": {
       "schema": {
        "type": "object"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "token",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "access_token": {
           "type": "string"
          },
          "token_type": {
           "type": "string"
          },
          "expires_in": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     }
    }
   }
  },
  "/v1/vehicles/enrichment": {
   "post": {
    "summary": "RF01: enriquecimento por placa (sem fonte oficial para Renavam e dono: devolvem null)",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "licensePlate",
         "clientRequestId"
        ],
        "properties": {
         "licensePlate": {
          "type": "string"
         },
         "uf": {
          "type": "string"
         },
         "clientRequestId": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "veículo",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     }
    }
   }
  },
  "/v1/debts/consults": {
   "post": {
    "summary": "RF02: criar consulta (assíncrona)",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/Pedido"
       }
      }
     }
    },
    "responses": {
     "202": {
      "description": "aceita, status PROCESSING",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     },
     "409": {
      "description": "DUPLICATE_REQUEST (traz a consulta original)"
     },
     "422": {
      "description": "STATE_NOT_SUPPORTED"
     },
     "429": {
      "description": "RATE_LIMITED (Retry-After)"
     }
    }
   },
   "get": {
    "summary": "RF05: buscar por clientRequestId",
    "parameters": [
     {
      "name": "clientRequestId",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "consulta",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Consulta"
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     }
    }
   }
  },
  "/v1/debts/consults/{idConsult}": {
   "get": {
    "summary": "RF05: buscar por idConsult",
    "parameters": [
     {
      "name": "idConsult",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "consulta",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Consulta"
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     }
    }
   }
  },
  "/v1/debts/consults/batch": {
   "post": {
    "summary": "RF04: lote (até 500 veículos)",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "vehicles": {
          "type": "array",
          "maxItems": 500,
          "items": {
           "$ref": "#/components/schemas/Pedido"
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "202": {
      "description": "lote aceito",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     }
    }
   }
  },
  "/v1/debts/consults/batch/{idBatch}": {
   "get": {
    "summary": "RF04: progresso do lote",
    "parameters": [
     {
      "name": "idBatch",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "progresso",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     }
    }
   }
  },
  "/v1/webhooks": {
   "post": {
    "summary": "Cadastrar URL de retorno (https público); devolve o secret do HMAC uma única vez",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "url": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "cadastrado",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     }
    }
   },
   "get": {
    "summary": "Ver URL cadastrada",
    "responses": {
     "200": {
      "description": "webhook",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Remover",
    "responses": {
     "200": {
      "description": "removido",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Erro"
        }
       }
      }
     }
    }
   }
  },
  "/v1/coverage": {
   "get": {
    "summary": "Cobertura por UF: campos obrigatórios, débitos e limitações; cenários do sandbox",
    "security": [],
    "responses": {
     "200": {
      "description": "tabela"
     }
    }
   }
  }
 }
}