{
  "openapi": "3.0.3",
  "info": {
    "title": "Tudo Envio API",
    "version": "1.0.0",
    "description": "API pública Tudo Envio — cotação de frete, emissão de etiquetas Correios, rastreamento, clientes, saldo/recarga PIX e fluxo POS (maquininha).\n\nAutenticação: envie o header `Authorization: Bearer te_live_...`. Gere o token em `/integracoes` ou pelo botão admin em `/admin/api-solicitacoes`.",
    "contact": {
      "name": "Tudo Envio",
      "url": "https://tudoenvio.com.br"
    }
  },
  "servers": [
    {
      "url": "https://tudoenvio.com.br/api/public/v1",
      "description": "Produção"
    },
    {
      "url": "https://tudo-envio-facil.lovable.app/api/public/v1",
      "description": "Preview"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Conta"
    },
    {
      "name": "Configuração"
    },
    {
      "name": "Frete"
    },
    {
      "name": "Etiquetas"
    },
    {
      "name": "POS"
    },
    {
      "name": "Rastreamento"
    },
    {
      "name": "Clientes"
    },
    {
      "name": "Saldo"
    }
  ],
  "paths": {
    "/me": {
      "get": {
        "tags": [
          "Conta"
        ],
        "summary": "Dados do usuário autenticado",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MeResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/saldo": {
      "get": {
        "tags": [
          "Conta"
        ],
        "summary": "Consultar saldo",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SaldoResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/config/plano": {
      "get": {
        "tags": [
          "Configuração"
        ],
        "summary": "Plano de markup vigente",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PlanoResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/config/embalagens": {
      "get": {
        "tags": [
          "Configuração"
        ],
        "summary": "Catálogo de embalagens ativas",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmbalagensResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/config/adicionais": {
      "get": {
        "tags": [
          "Configuração"
        ],
        "summary": "Serviços adicionais (seguro, AR, mão-própria)",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AdicionaisResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/frete/cotacao": {
      "post": {
        "tags": [
          "Frete"
        ],
        "summary": "Cotar frete",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CotacaoRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CotacaoResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/etiquetas": {
      "get": {
        "tags": [
          "Etiquetas"
        ],
        "summary": "Listar etiquetas emitidas",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "etiquetas": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Etiqueta"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Etiquetas"
        ],
        "summary": "Emitir etiqueta (debita saldo)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmitirEtiquetaRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Criado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "etiqueta": {
                      "$ref": "#/components/schemas/Etiqueta"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "description": "Saldo insuficiente",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/etiquetas/{id}": {
      "get": {
        "tags": [
          "Etiquetas"
        ],
        "summary": "Consultar etiqueta",
        "parameters": [
          {
            "$ref": "#/components/parameters/EtiquetaId"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "etiqueta": {
                      "$ref": "#/components/schemas/Etiqueta"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/etiquetas/{id}/pdf": {
      "get": {
        "tags": [
          "Etiquetas"
        ],
        "summary": "URLs assinadas dos PDFs (etiqueta, declaração, recibo)",
        "parameters": [
          {
            "$ref": "#/components/parameters/EtiquetaId"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "etiqueta_pdf_url": {
                      "type": "string"
                    },
                    "declaracao_pdf_url": {
                      "type": "string"
                    },
                    "recibo_pdf_url": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/etiquetas/{id}/pdfs": {
      "post": {
        "tags": [
          "Etiquetas"
        ],
        "summary": "Gera os PDFs faltantes e devolve todas as URLs assinadas",
        "description": "Use quando algum campo `*_pdf_url` vier vazio (etiquetas antigas). Gera o combinado A6/A4 e o recibo (PDF + JSON) se ainda não existirem no storage.",
        "parameters": [
          {
            "$ref": "#/components/parameters/EtiquetaId"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "etiqueta_pdf_url": {
                      "type": "string"
                    },
                    "declaracao_pdf_url": {
                      "type": "string"
                    },
                    "etiqueta_completa_pdf_url": {
                      "type": "string"
                    },
                    "etiqueta_completa_a4_pdf_url": {
                      "type": "string"
                    },
                    "recibo_pdf_url": {
                      "type": "string"
                    },
                    "recibo_json_url": {
                      "type": "string"
                    },
                    "avisos": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/etiquetas/{id}/email": {
      "post": {
        "tags": [
          "Etiquetas"
        ],
        "summary": "Envia o recibo da etiqueta por e-mail",
        "description": "Mesmo envio do painel/totem: anexa o recibo 80mm e, opcionalmente, o combinado A6 (etiqueta + declaração). Arquivos que ainda não existem são gerados sob demanda.",
        "parameters": [
          {
            "$ref": "#/components/parameters/EtiquetaId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "example": "cliente@exemplo.com"
                  },
                  "anexos": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "recibo",
                        "combinado"
                      ]
                    },
                    "description": "Padrão: [\"recibo\"].",
                    "example": [
                      "recibo",
                      "combinado"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "id": {
                      "type": "string"
                    },
                    "enviado_para": {
                      "type": "string"
                    },
                    "anexos": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/etiquetas/{id}/recibo-json": {
      "get": {
        "tags": [
          "Etiquetas"
        ],
        "summary": "Recibo estruturado (tudoenvio.recibo/v2) para impressão nativa",
        "parameters": [
          {
            "$ref": "#/components/parameters/EtiquetaId"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "recibo": {
                      "type": "object",
                      "additionalProperties": true
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/pos/etiquetas": {
      "post": {
        "tags": [
          "POS"
        ],
        "summary": "Emitir etiqueta com pagamento externo (maquininha)",
        "description": "Fluxo POS: paga na maquininha (SDK Cielo/Stone/PagSeguro) e envia NSU/TID já autorizados. Não usa saldo.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string"
            },
            "description": "Chave de idempotência (recomenda-se reutilizar o NSU)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PosEtiquetaRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Criado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PosEtiquetaResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/rastreamento/{codigo}": {
      "get": {
        "tags": [
          "Rastreamento"
        ],
        "summary": "Rastrear objeto pelo código",
        "parameters": [
          {
            "name": "codigo",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "example": "BR123456789BR"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RastreamentoResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/clientes": {
      "get": {
        "tags": [
          "Clientes"
        ],
        "summary": "Listar clientes",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "clientes": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Cliente"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Clientes"
        ],
        "summary": "Cadastrar cliente",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClienteRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Criado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "cliente": {
                      "$ref": "#/components/schemas/Cliente"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/saldo/recarga": {
      "post": {
        "tags": [
          "Saldo"
        ],
        "summary": "Criar recarga PIX",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "valor_centavos"
                ],
                "properties": {
                  "valor_centavos": {
                    "type": "integer",
                    "minimum": 500,
                    "example": 5000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Criado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecargaResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/saldo/recarga/{id}": {
      "get": {
        "tags": [
          "Saldo"
        ],
        "summary": "Consultar status de recarga",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecargaResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "te_live_..."
      }
    },
    "parameters": {
      "EtiquetaId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Token ausente ou inválido",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "NotFound": {
        "description": "Não encontrado",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "ValidationError": {
        "description": "Erro de validação",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    },
    "schemas": {
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": false
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "example": "VALIDATION_ERROR"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "MeResponse": {
        "type": "object",
        "properties": {
          "user": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string",
                "nullable": true
              },
              "email": {
                "type": "string",
                "nullable": true
              }
            }
          }
        }
      },
      "SaldoResponse": {
        "type": "object",
        "properties": {
          "saldo": {
            "type": "number",
            "example": 152.4
          },
          "currency": {
            "type": "string",
            "example": "BRL"
          }
        }
      },
      "PlanoResponse": {
        "type": "object",
        "properties": {
          "plano": {
            "type": "object",
            "nullable": true,
            "properties": {
              "nome": {
                "type": "string"
              },
              "tipo": {
                "type": "string",
                "example": "percentual"
              },
              "valor": {
                "type": "number"
              },
              "servicos": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "Embalagem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "nome": {
            "type": "string"
          },
          "tipo": {
            "type": "string"
          },
          "descricao": {
            "type": "string",
            "nullable": true
          },
          "largura_cm": {
            "type": "number",
            "nullable": true
          },
          "altura_cm": {
            "type": "number",
            "nullable": true
          },
          "comprimento_cm": {
            "type": "number",
            "nullable": true
          },
          "preco": {
            "type": "number"
          },
          "estoque": {
            "type": "integer"
          }
        }
      },
      "EmbalagensResponse": {
        "type": "object",
        "properties": {
          "embalagens": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Embalagem"
            }
          }
        }
      },
      "AdicionaisResponse": {
        "type": "object",
        "properties": {
          "seguro": {
            "type": "object",
            "properties": {
              "habilitado": {
                "type": "boolean"
              },
              "percentual": {
                "type": "number"
              },
              "minimo": {
                "type": "number"
              }
            }
          },
          "mao_propria": {
            "type": "object",
            "properties": {
              "habilitado": {
                "type": "boolean"
              },
              "valor": {
                "type": "number"
              }
            }
          },
          "aviso_recebimento": {
            "type": "object",
            "properties": {
              "habilitado": {
                "type": "boolean"
              },
              "valor": {
                "type": "number"
              }
            }
          }
        }
      },
      "CotacaoRequest": {
        "type": "object",
        "required": [
          "cep_origem",
          "cep_destino",
          "peso"
        ],
        "properties": {
          "cep_origem": {
            "type": "string",
            "example": "01001000"
          },
          "cep_destino": {
            "type": "string",
            "example": "20040020"
          },
          "peso": {
            "type": "number",
            "example": 1.5
          },
          "comprimento": {
            "type": "number",
            "example": 20
          },
          "largura": {
            "type": "number",
            "example": 15
          },
          "altura": {
            "type": "number",
            "example": 10
          },
          "valor_declarado": {
            "type": "number",
            "example": 0
          }
        }
      },
      "CotacaoResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "payload": {
            "type": "object",
            "additionalProperties": true,
            "description": "Cópia exata do JSON enviado na requisição (nenhum campo é adicionado, removido ou renomeado)."
          },
          "recebido": {
            "type": "object",
            "additionalProperties": true,
            "description": "Alias de payload, mantido para compatibilidade."
          },
          "payload_normalizado": {
            "type": "object",
            "description": "Valores efetivamente usados no cálculo.",
            "properties": {
              "cep_origem": {
                "type": "string"
              },
              "cep_destino": {
                "type": "string"
              },
              "peso_kg": {
                "type": "number"
              },
              "comprimento_cm": {
                "type": "number",
                "nullable": true
              },
              "largura_cm": {
                "type": "number",
                "nullable": true
              },
              "altura_cm": {
                "type": "number",
                "nullable": true
              },
              "valor_declarado": {
                "type": "number"
              },
              "servico": {
                "type": "string",
                "nullable": true
              },
              "codigo_servico": {
                "type": "string",
                "nullable": true
              },
              "adicionais": {
                "type": "object",
                "properties": {
                  "seguro": {
                    "type": "boolean"
                  },
                  "mao_propria": {
                    "type": "boolean"
                  },
                  "aviso_recebimento": {
                    "type": "boolean"
                  }
                }
              },
              "embalagens": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "nome": {
                      "type": "string"
                    },
                    "quantidade": {
                      "type": "integer"
                    },
                    "preco_unitario": {
                      "type": "number"
                    },
                    "subtotal": {
                      "type": "number"
                    }
                  }
                }
              }
            }
          },
          "cotacoes": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "servico": {
                  "type": "string"
                },
                "codigo_servico": {
                  "type": "string"
                },
                "valor": {
                  "type": "number"
                },
                "prazo": {
                  "type": "integer"
                },
                "erro": {
                  "type": "string",
                  "nullable": true
                },
                "adicionais": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "codigo": {
                        "type": "string"
                      },
                      "label": {
                        "type": "string"
                      },
                      "valor": {
                        "type": "number"
                      },
                      "icone": {
                        "type": "string",
                        "example": "seguro",
                        "description": "Nome curto do ícone do adicional."
                      },
                      "icone_url": {
                        "type": "string",
                        "format": "uri",
                        "example": "https://tudoenvio.com.br/api-assets/adicionais/seguro.svg",
                        "description": "URL pública do SVG do ícone."
                      }
                    }
                  }
                },
                "total_adicionais": {
                  "type": "number"
                },
                "embalagens": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string"
                      },
                      "nome": {
                        "type": "string"
                      },
                      "quantidade": {
                        "type": "integer"
                      },
                      "preco_unitario": {
                        "type": "number"
                      },
                      "subtotal": {
                        "type": "number"
                      }
                    }
                  }
                },
                "total_embalagens": {
                  "type": "number"
                },
                "valor_total": {
                  "type": "number"
                }
              }
            }
          },
          "adicionais": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "codigo": {
                  "type": "string"
                },
                "label": {
                  "type": "string"
                },
                "valor": {
                  "type": "number"
                },
                "icone": {
                  "type": "string",
                  "example": "seguro",
                  "description": "Nome curto do ícone do adicional."
                },
                "icone_url": {
                  "type": "string",
                  "format": "uri",
                  "example": "https://tudoenvio.com.br/api-assets/adicionais/seguro.svg",
                  "description": "URL pública do SVG do ícone."
                }
              }
            }
          },
          "total_adicionais": {
            "type": "number"
          },
          "embalagens": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "nome": {
                  "type": "string"
                },
                "quantidade": {
                  "type": "integer"
                },
                "preco_unitario": {
                  "type": "number"
                },
                "subtotal": {
                  "type": "number"
                }
              }
            }
          },
          "total_embalagens": {
            "type": "number"
          },
          "pagamento_pix": {
            "type": "object",
            "nullable": true,
            "description": "Somente quando o request traz pagamento: \"pix\".",
            "properties": {
              "pagamento_id": {
                "type": "string"
              },
              "payment_id": {
                "type": "string",
                "nullable": true
              },
              "qr_code": {
                "type": "string"
              },
              "qr_code_base64": {
                "type": "string"
              },
              "ticket_url": {
                "type": "string",
                "nullable": true
              },
              "valor": {
                "type": "number"
              },
              "expira_em": {
                "type": "string",
                "nullable": true
              },
              "pago": {
                "type": "boolean"
              },
              "status": {
                "type": "string"
              },
              "teste": {
                "type": "boolean"
              },
              "consulta_url": {
                "type": "string"
              }
            }
          }
        }
      },
      "Endereco": {
        "type": "object",
        "required": [
          "nome",
          "documento",
          "cep",
          "endereco",
          "numero",
          "bairro",
          "cidade",
          "uf"
        ],
        "properties": {
          "nome": {
            "type": "string"
          },
          "documento": {
            "type": "string"
          },
          "telefone": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "cep": {
            "type": "string"
          },
          "endereco": {
            "type": "string"
          },
          "numero": {
            "type": "string"
          },
          "complemento": {
            "type": "string"
          },
          "bairro": {
            "type": "string"
          },
          "cidade": {
            "type": "string"
          },
          "uf": {
            "type": "string",
            "example": "SP"
          }
        }
      },
      "Pacote": {
        "type": "object",
        "required": [
          "peso_gramas",
          "comprimento_cm",
          "largura_cm",
          "altura_cm"
        ],
        "properties": {
          "peso_gramas": {
            "type": "integer",
            "example": 500
          },
          "comprimento_cm": {
            "type": "number",
            "example": 20
          },
          "largura_cm": {
            "type": "number",
            "example": 15
          },
          "altura_cm": {
            "type": "number",
            "example": 10
          }
        }
      },
      "EmitirEtiquetaRequest": {
        "type": "object",
        "required": [
          "servico",
          "remetente",
          "destinatario",
          "pacote"
        ],
        "properties": {
          "servico": {
            "type": "string",
            "example": "03298"
          },
          "remetente": {
            "$ref": "#/components/schemas/Endereco"
          },
          "destinatario": {
            "$ref": "#/components/schemas/Endereco"
          },
          "pacote": {
            "$ref": "#/components/schemas/Pacote"
          },
          "adicionais": {
            "type": "object",
            "properties": {
              "ar": {
                "type": "boolean"
              },
              "maos_proprias": {
                "type": "boolean"
              },
              "valor_declarado": {
                "type": "number"
              }
            }
          }
        }
      },
      "Etiqueta": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "codigo_rastreamento": {
            "type": "string",
            "example": "BR123456789BR"
          },
          "servico": {
            "type": "string"
          },
          "codigo_servico": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "origem": {
            "type": "string"
          },
          "forma_pagamento": {
            "type": "string"
          },
          "valor": {
            "type": "number"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "destinatario": {
            "type": "object",
            "properties": {
              "nome": {
                "type": "string",
                "nullable": true
              },
              "cidade": {
                "type": "string",
                "nullable": true
              },
              "uf": {
                "type": "string",
                "nullable": true
              },
              "cep": {
                "type": "string",
                "nullable": true
              }
            }
          },
          "etiqueta_pdf_url": {
            "type": "string",
            "description": "URL assinada da etiqueta A4 (vazia se ainda não gerada)"
          },
          "declaracao_pdf_url": {
            "type": "string",
            "description": "URL assinada da declaração (DCE)"
          },
          "etiqueta_completa_pdf_url": {
            "type": "string",
            "description": "URL assinada do combinado A6 (etiqueta + declaração). Gerado sob demanda na resposta quando ainda não existir; cai para A4 quando não há A6."
          },
          "recibo_pdf_url": {
            "type": "string",
            "description": "URL assinada do recibo de postagem"
          },
          "recibo_json_url": {
            "type": "string"
          },
          "recibo": {
            "type": "object",
            "nullable": true,
            "description": "Payload completo do recibo de postagem, schema tudoenvio.recibo/v2 (mesmo objeto de GET /etiquetas/{id} e do JSON enviado à impressora). Inclui prepostagem (com codigoServico, idPrepostagemCorreios, dataPrevista), rastreio, remetente e destinatario com endereço completo (documento, telefone, email, cep, logradouro, numero, complemento, bairro, enderecoLinha), itens, embalagens, totais (frete, adicionais, embalagens, total), extras.valores (seguro, maoPropria, avisoRecebimento) e empresa. null quando não disponível."
          }
        }
      },
      "PosEtiquetaRequest": {
        "type": "object",
        "required": [
          "servico",
          "remetente",
          "destinatario",
          "pacote",
          "pagamento"
        ],
        "properties": {
          "servico": {
            "type": "string"
          },
          "remetente": {
            "$ref": "#/components/schemas/Endereco"
          },
          "destinatario": {
            "$ref": "#/components/schemas/Endereco"
          },
          "pacote": {
            "$ref": "#/components/schemas/Pacote"
          },
          "adicionais": {
            "type": "object",
            "properties": {
              "ar": {
                "type": "boolean"
              },
              "maos_proprias": {
                "type": "boolean"
              },
              "valor_declarado": {
                "type": "number"
              }
            }
          },
          "pagamento": {
            "type": "object",
            "required": [
              "metodo",
              "valor_centavos",
              "nsu"
            ],
            "properties": {
              "metodo": {
                "type": "string",
                "enum": [
                  "credito",
                  "debito",
                  "pix",
                  "dinheiro"
                ]
              },
              "valor_centavos": {
                "type": "integer"
              },
              "nsu": {
                "type": "string"
              },
              "tid": {
                "type": "string"
              },
              "bandeira": {
                "type": "string"
              },
              "parcelas": {
                "type": "integer"
              },
              "autorizacao": {
                "type": "string"
              }
            }
          }
        }
      },
      "PosEtiquetaResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "etiqueta": {
            "$ref": "#/components/schemas/Etiqueta"
          },
          "recibo_json_url": {
            "type": "string"
          },
          "idempotente": {
            "type": "boolean"
          }
        }
      },
      "RastreamentoResponse": {
        "type": "object",
        "properties": {
          "codigo": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "eventos": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "data": {
                  "type": "string"
                },
                "descricao": {
                  "type": "string"
                },
                "local": {
                  "type": "string",
                  "nullable": true
                }
              }
            }
          }
        }
      },
      "Cliente": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "nome": {
            "type": "string"
          },
          "documento": {
            "type": "string"
          },
          "cep": {
            "type": "string"
          },
          "cidade": {
            "type": "string"
          },
          "uf": {
            "type": "string"
          }
        }
      },
      "ClienteRequest": {
        "type": "object",
        "required": [
          "nome",
          "documento",
          "cep",
          "endereco",
          "numero",
          "bairro",
          "cidade",
          "uf"
        ],
        "properties": {
          "nome": {
            "type": "string"
          },
          "documento": {
            "type": "string"
          },
          "telefone": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "cep": {
            "type": "string"
          },
          "endereco": {
            "type": "string"
          },
          "numero": {
            "type": "string"
          },
          "complemento": {
            "type": "string"
          },
          "bairro": {
            "type": "string"
          },
          "cidade": {
            "type": "string"
          },
          "uf": {
            "type": "string"
          }
        }
      },
      "RecargaResponse": {
        "type": "object",
        "properties": {
          "recarga": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "valor": {
                "type": "number"
              },
              "status": {
                "type": "string"
              },
              "qr_code": {
                "type": "string"
              },
              "qr_code_base64": {
                "type": "string"
              },
              "expira_em": {
                "type": "string",
                "format": "date-time"
              },
              "pago_em": {
                "type": "string",
                "format": "date-time",
                "nullable": true
              },
              "created_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        }
      }
    }
  }
}