openapi: 3.0.3
info:
  title: 4Axon APIs – Fluxos (OCR, SDK, Weblink)
  version: 1.0.0
  description: |
    Especificação dos fluxos PF APP e PF/PJ Weblink.
servers:
  - url: https://api.4axon.kubeapps.adviseu.it/
security:
  - bearerAuth: []
tags:
  - name: Fluxo SDK
    description: Validação com SDK no app (início de protocolo PF)
  - name: Fluxo OCR
    description: Envio de arquivo e extração de campos (início de processo)
  - name: Fluxo Weblink
    description: Jornada via link para web application (início de processo)
paths:
  /v1/sdk/validations:
    post:
      tags: [Fluxo SDK]
      summary: Iniciar validação via SDK
      description: Inicia uma validação PF via SDK. Requer header X-Api-Key.
      security:
        - bearerAuth: []
          sdkApiKey: []
      callbacks:
        validationStatus:
          '{$request.body#/webhookUrl}':
            post:
              summary: Receber resultado da validação via webhook (SDK)
              requestBody:
                required: true
                content:
                  application/json:
                    schema:
                      $ref: '#/components/schemas/SdkWebhookPayload'
              responses:
                '200':
                  description: Webhook recebido
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SdkValidationRequest'
      responses:
        '201':
          description: Validação criada
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SdkValidationCreated'
        '400':
          description: Requisição inválida
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Não autorizado
  /v1/weblink/validations:
    post:
      tags: [Fluxo OCR, Fluxo Weblink]
      summary: Iniciar validação via Weblink
      description: Inicia uma validação com jornada via link (upload de arquivo quando aplicável).
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required: [file]
              properties:
                file:
                  type: string
                  format: binary
                cnpj:
                  type: string
                productId:
                  type: string
                webhookUrl:
                  type: string
                  format: uri
                simulate:
                  type: boolean
            encoding:
              file:
                contentType: application/pdf
      responses:
        '201':
          description: Validação criada
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WeblinkValidationCreated'
        '400':
          description: Requisição inválida
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Não autorizado
      callbacks:
        validationStatus:
          '{$request.body#/webhookUrl}':
            post:
              summary: Receber resultado da validação via webhook (Weblink)
              requestBody:
                required: true
                content:
                  application/json:
                    schema:
                      $ref: '#/components/schemas/WeblinkWebhookPayload'
              responses:
                '200':
                  description: Webhook recebido
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
    sdkApiKey:
      type: apiKey
      in: header
      name: X-Api-Key
  schemas:
    Error:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
    SdkValidationRequest:
      type: object
      required: [codcli, codprod, cpf]
      properties:
        codcli:
          type: string
        codprod:
          type: string
        cpf:
          type: string
        email:
          type: string
        telefone:
          type: string
        webhookUrl:
          type: string
          format: uri
    SdkValidationCreated:
      type: object
      properties:
        validationId:
          type: string
        status:
          type: string
          enum: [PENDING]
        webhookRegistered:
          type: boolean
    Indicator:
      type: object
      properties:
        enabled:
          type: boolean
        provider:
          type: string
        value:
          type: integer
        result:
          type: string
    WeblinkValidationCreated:
      type: object
      properties:
        validationId:
          type: string
        status:
          type: string
          enum: [PENDING]
        journeyUrl:
          type: string
    OcrGroup:
      type: object
      properties:
        enabled:
          type: boolean
        result:
          $ref: '#/components/schemas/OcrResult'
    SdkWebhookPayload:
      type: object
      properties:
        Protocolo:
          type: string
        Dtprocessamento:
          type: string
        sdkDoc:
          $ref: '#/components/schemas/Indicator'
        sdkLiveness:
          $ref: '#/components/schemas/Indicator'
        sdkDevice:
          $ref: '#/components/schemas/Indicator'
        apiDoc:
          $ref: '#/components/schemas/Indicator'
        apiLiveness:
          $ref: '#/components/schemas/Indicator'
        apiDevice:
          $ref: '#/components/schemas/Indicator'
    WeblinkWebhookPayload:
      type: object
      properties:
        Protocolo:
          type: string
        Dtprocessamento:
          type: string
        ocr:
          $ref: '#/components/schemas/OcrGroup'
        idQSA:
          type: integer
        sdkDoc:
          $ref: '#/components/schemas/Indicator'
        sdkLiveness:
          $ref: '#/components/schemas/Indicator'
        sdkDevice:
          $ref: '#/components/schemas/Indicator'
        apiDoc:
          $ref: '#/components/schemas/Indicator'
        apiLiveness:
          $ref: '#/components/schemas/Indicator'
        apiDevice:
          $ref: '#/components/schemas/Indicator'
    OcrField:
      type: object
      properties:
        name:
          type: string
        value:
          type: string
        confidence:
          type: number
    OcrResult:
      type: object
      properties:
        rawText:
          type: string
        fields:
          type: array
          items:
            $ref: '#/components/schemas/OcrField'
        metadata:
          type: object
