{
  "openapi": "3.1.0",
  "info": {
    "title": "IntegraCFDI · API pública",
    "version": "1.0.0",
    "description": "Contrato público de endpoints Client y anónimos. Sandbox exclusivamente. No hay registro público ni recuperación Client de XML. CORS admite exclusivamente https://developers.cfdicomplete.com para solicitudes desde el navegador."
  },
  "servers": [
    {
      "url": "https://sandbox-integracfdi.cfdicomplete.com",
      "description": "Sandbox autorizado"
    }
  ],
  "tags": [
    {
      "name": "Servicio"
    },
    {
      "name": "Autenticación"
    },
    {
      "name": "Timbrado"
    },
    {
      "name": "Folios"
    },
    {
      "name": "Operaciones"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "operationId": "get_health",
        "tags": [
          "Servicio"
        ],
        "summary": "Disponibilidad HTTP; no consulta SQL ni PAC",
        "description": "Disponibilidad HTTP; no consulta SQL ni PAC",
        "security": [],
        "responses": {
          "200": {
            "description": "Servicio disponible",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "const": "healthy",
                      "type": "string"
                    },
                    "service": {
                      "const": "IntegraCFDI.Api",
                      "type": "string"
                    },
                    "version": {
                      "type": "string",
                      "description": "Versión",
                      "example": "1.0.0"
                    }
                  },
                  "required": [
                    "status",
                    "service",
                    "version"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/token": {
      "post": {
        "operationId": "post_api_v1_auth_token",
        "tags": [
          "Autenticación"
        ],
        "summary": "Obtener JWT por 3600 segundos",
        "description": "Obtener JWT por 3600 segundos",
        "security": [],
        "responses": {
          "200": {
            "description": "Token válido; no hay refresh token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenResponse"
                }
              }
            }
          },
          "400": {
            "description": "Datos o filtros inválidos; puede incluir errors de validación",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Autenticación rechazada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "description": "Credenciales no válidas"
                    }
                  },
                  "required": [
                    "message"
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Cuota o capacidad agotada; Retry-After si está presente",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Espera indicada, cuando exista"
              }
            }
          },
          "500": {
            "description": "Error interno sanitizado",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TokenRequest"
              },
              "example": {
                "username": "cliente-demo",
                "password": "CONTRASENA_FICTICIA_NO_USAR"
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/me": {
      "get": {
        "operationId": "get_api_v1_auth_me",
        "tags": [
          "Autenticación"
        ],
        "summary": "Consultar identidad autenticada",
        "description": "Consultar identidad autenticada",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Identidad propia",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CurrentUser"
                }
              }
            }
          },
          "400": {
            "description": "Datos o filtros inválidos; puede incluir errors de validación",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Sin autenticación válida; puede no tener cuerpo o contener message"
          },
          "403": {
            "description": "Rol no autorizado; puede no tener cuerpo"
          },
          "429": {
            "description": "Cuota o capacidad agotada; Retry-After si está presente",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Espera indicada, cuando exista"
              }
            }
          },
          "500": {
            "description": "Error interno sanitizado",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/change-password": {
      "post": {
        "operationId": "post_api_v1_auth_change_password",
        "tags": [
          "Autenticación"
        ],
        "summary": "Cambiar contraseña propia e invalidar tokens anteriores",
        "description": "Cambiar contraseña propia e invalidar tokens anteriores",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "204": {
            "description": "Contraseña actualizada, sin cuerpo"
          },
          "400": {
            "description": "Datos o filtros inválidos; puede incluir errors de validación",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Sin autenticación válida; puede no tener cuerpo o contener message"
          },
          "403": {
            "description": "Rol no autorizado; puede no tener cuerpo"
          },
          "409": {
            "description": "Conflicto concurrente",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Cuota o capacidad agotada; Retry-After si está presente",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Espera indicada, cuando exista"
              }
            }
          },
          "500": {
            "description": "Error interno sanitizado",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChangePassword"
              }
            }
          }
        }
      }
    },
    "/api/v1/folios/balance": {
      "get": {
        "operationId": "get_api_v1_folios_balance",
        "tags": [
          "Folios"
        ],
        "summary": "Consultar saldo propio",
        "description": "Consultar saldo propio",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Saldo disponible y reservado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Balance"
                }
              }
            }
          },
          "400": {
            "description": "Datos o filtros inválidos; puede incluir errors de validación",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Sin autenticación válida; puede no tener cuerpo o contener message"
          },
          "403": {
            "description": "Rol no autorizado; puede no tener cuerpo"
          },
          "404": {
            "description": "Saldo no encontrado",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Cuota o capacidad agotada; Retry-After si está presente",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Espera indicada, cuando exista"
              }
            }
          },
          "500": {
            "description": "Error interno sanitizado",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/folios/transactions": {
      "get": {
        "operationId": "get_api_v1_folios_transactions",
        "tags": [
          "Folios"
        ],
        "summary": "Consultar movimientos propios paginados",
        "description": "Consultar movimientos propios paginados",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Historial financiero propio",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MovementPage"
                }
              }
            }
          },
          "400": {
            "description": "Datos o filtros inválidos; puede incluir errors de validación",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Sin autenticación válida; puede no tener cuerpo o contener message"
          },
          "403": {
            "description": "Rol no autorizado; puede no tener cuerpo"
          },
          "429": {
            "description": "Cuota o capacidad agotada; Retry-After si está presente",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Espera indicada, cuando exista"
              }
            }
          },
          "500": {
            "description": "Error interno sanitizado",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "fromUtc",
            "in": "query",
            "description": "Desde inclusivo, UTC con Z",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "toUtc",
            "in": "query",
            "description": "Hasta exclusivo, UTC con Z",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "Credit",
                "Adjustment",
                "Reserve",
                "Consume",
                "Release"
              ]
            }
          }
        ]
      }
    },
    "/api/v1/cfdi/operations": {
      "get": {
        "operationId": "get_api_v1_cfdi_operations",
        "tags": [
          "Operaciones"
        ],
        "summary": "Consultar operaciones propias; excluye Rejected por defecto",
        "description": "Consultar operaciones propias; excluye Rejected por defecto",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Lista paginada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OperationPage"
                }
              }
            }
          },
          "400": {
            "description": "Datos o filtros inválidos; puede incluir errors de validación",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Sin autenticación válida; puede no tener cuerpo o contener message"
          },
          "403": {
            "description": "Rol no autorizado; puede no tener cuerpo"
          },
          "429": {
            "description": "Cuota o capacidad agotada; Retry-After si está presente",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Espera indicada, cuando exista"
              }
            }
          },
          "500": {
            "description": "Error interno sanitizado",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "fromUtc",
            "in": "query",
            "description": "Desde inclusivo, UTC con Z",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "toUtc",
            "in": "query",
            "description": "Hasta exclusivo, UTC con Z",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Filtro explícito Rejected habilita consulta técnica del propietario",
            "schema": {
              "type": "string",
              "enum": [
                "Received",
                "Reserved",
                "Processing",
                "Uncertain",
                "Stamped",
                "Rejected"
              ]
            }
          }
        ]
      }
    },
    "/api/v1/cfdi/operations/{id}": {
      "get": {
        "operationId": "get_api_v1_cfdi_operations__id_",
        "tags": [
          "Operaciones"
        ],
        "summary": "Consultar metadatos de operación propia",
        "description": "Consultar metadatos de operación propia",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "No incluye XML, hash ni clave de idempotencia",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Operation"
                }
              }
            }
          },
          "400": {
            "description": "Datos o filtros inválidos; puede incluir errors de validación",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Sin autenticación válida; puede no tener cuerpo o contener message"
          },
          "403": {
            "description": "Rol no autorizado; puede no tener cuerpo"
          },
          "404": {
            "description": "Operación ajena o inexistente",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Cuota o capacidad agotada; Retry-After si está presente",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Espera indicada, cuando exista"
              }
            }
          },
          "500": {
            "description": "Error interno sanitizado",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Identificador UUID",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/cfdi/stamp": {
      "post": {
        "operationId": "post_api_v1_cfdi_stamp",
        "tags": [
          "Timbrado"
        ],
        "summary": "Timbrar CFDI 4.0 previamente firmado (Client)",
        "description": "Sólo Client activo. No hace sellado. SHA-256 sobre bytes originales; mismo usuario/clave/bytes recupera estado, hash distinto 409. Sin reintentos automáticos. Cuota inicial 3/minuto, concurrencia 1; un éxito consume exactamente un folio.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Éxito confirmado inicial o repetición sin XML",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/StampSuccess"
                    },
                    {
                      "$ref": "#/components/schemas/StampRepeated"
                    }
                  ]
                }
              }
            }
          },
          "202": {
            "description": "Pendiente: no reenviar ni cambiar clave",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StampPending"
                }
              }
            }
          },
          "400": {
            "description": "Datos o filtros inválidos; puede incluir errors de validación",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Sin autenticación válida; puede no tener cuerpo o contener message"
          },
          "403": {
            "description": "Rol no autorizado; puede no tener cuerpo"
          },
          "409": {
            "description": "Idempotencia, saldo o estado conflictivo",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "413": {
            "description": "Más de 5 MiB; IIS puede rechazar antes de la aplicación"
          },
          "415": {
            "description": "Se requiere application/xml"
          },
          "422": {
            "description": "Rechazo definitivo; reserva liberada; mensaje sólo si disponible y seguro",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StampRejected"
                }
              }
            }
          },
          "429": {
            "description": "Cuota o capacidad agotada; Retry-After si está presente",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                },
                "description": "Espera indicada, cuando exista"
              }
            }
          },
          "500": {
            "description": "Error interno sanitizado",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "No enviado confirmado, o persistencia no confirmada; distinguir error.code",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/StampRejected"
                    },
                    {
                      "$ref": "#/components/schemas/PersistenceUnconfirmed"
                    }
                  ]
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Clave opaca estable, sin espacios ni comas. No regenerar ante incertidumbre.",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200,
              "pattern": "^[!-+\\--~]+$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Bytes originales de XML UTF-8 firmado y sin timbre. No envíe KEY ni contraseñas. Máximo 5 MiB.",
          "content": {
            "application/xml": {
              "schema": {
                "type": "string",
                "maxLength": 5242880,
                "description": "Límite operativo expresado en bytes; maxLength sólo orientativo para texto. No contiene un comprobante de prueba ejecutable."
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {
      "TokenRequest": {
        "type": "object",
        "properties": {
          "username": {
            "type": "string",
            "description": "Usuario Client",
            "maxLength": 100,
            "minLength": 1
          },
          "password": {
            "type": "string",
            "description": "Contraseña",
            "minLength": 1,
            "maxLength": 1024,
            "format": "password",
            "writeOnly": true
          }
        },
        "required": [
          "username",
          "password"
        ]
      },
      "TokenResponse": {
        "type": "object",
        "properties": {
          "accessToken": {
            "type": "string",
            "description": "JWT efímero; custodiar en memoria"
          },
          "tokenType": {
            "const": "Bearer",
            "type": "string"
          },
          "expiresIn": {
            "type": "integer",
            "example": 3600
          }
        },
        "required": [
          "accessToken",
          "tokenType",
          "expiresIn"
        ]
      },
      "CurrentUser": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Identificador UUID",
            "format": "uuid"
          },
          "username": {
            "type": "string",
            "description": "Usuario"
          },
          "displayName": {
            "type": "string",
            "description": "Nombre visible"
          },
          "role": {
            "type": "string",
            "description": "Rol autenticado",
            "example": "Client"
          }
        },
        "required": [
          "id",
          "username",
          "displayName",
          "role"
        ]
      },
      "ChangePassword": {
        "type": "object",
        "properties": {
          "currentPassword": {
            "type": "string",
            "description": "Contraseña actual",
            "maxLength": 1024,
            "minLength": 1,
            "format": "password",
            "writeOnly": true
          },
          "newPassword": {
            "type": "string",
            "description": "Nueva contraseña; invalida tokens previos",
            "minLength": 12,
            "maxLength": 128,
            "format": "password",
            "writeOnly": true
          }
        },
        "required": [
          "currentPassword",
          "newPassword"
        ]
      },
      "Balance": {
        "type": "object",
        "properties": {
          "availableFolios": {
            "type": "integer",
            "format": "int64",
            "description": "Disponibles"
          },
          "reservedFolios": {
            "type": "integer",
            "format": "int64",
            "description": "Reservados"
          },
          "updatedAtUtc": {
            "type": "string",
            "description": "Fecha UTC ISO-8601",
            "format": "date-time"
          }
        },
        "required": [
          "availableFolios",
          "reservedFolios",
          "updatedAtUtc"
        ]
      },
      "Diagnostic": {
        "type": "object",
        "properties": {
          "field": {
            "type": "string",
            "description": "Campo"
          },
          "reportedValue": {
            "type": [
              "string",
              "null"
            ]
          },
          "expectedValue": {
            "type": [
              "string",
              "null"
            ]
          },
          "allowedRange": {
            "type": [
              "string",
              "null"
            ]
          },
          "rule": {
            "type": "string",
            "description": "Regla"
          },
          "calculation": {
            "type": [
              "string",
              "null"
            ]
          },
          "suggestion": {
            "type": [
              "string",
              "null"
            ]
          },
          "ruleSource": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "field",
          "reportedValue",
          "expectedValue",
          "allowedRange",
          "rule",
          "calculation",
          "suggestion",
          "ruleSource"
        ]
      },
      "PacError": {
        "type": "object",
        "properties": {
          "source": {
            "type": "string",
            "description": "Origen; no sustituir código PAC"
          },
          "code": {
            "type": [
              "string",
              "null"
            ]
          },
          "message": {
            "type": "string",
            "description": "Mensaje seguro o indicación de indisponibilidad"
          },
          "messageSanitized": {
            "type": "boolean"
          },
          "originalMessageAvailable": {
            "type": "boolean"
          },
          "diagnostics": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Diagnostic"
            }
          }
        },
        "required": [
          "source",
          "code",
          "message"
        ]
      },
      "Operation": {
        "type": "object",
        "properties": {
          "operationId": {
            "type": "string",
            "description": "Identificador UUID",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "description": "Estado",
            "enum": [
              "Received",
              "Reserved",
              "Processing",
              "Uncertain",
              "Stamped",
              "Rejected"
            ]
          },
          "uuid": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "pacCode": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAtUtc": {
            "type": "string",
            "description": "Fecha UTC ISO-8601",
            "format": "date-time"
          },
          "updatedAtUtc": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "foliosReserved": {
            "type": "integer",
            "format": "int64",
            "description": "Reserva actual"
          },
          "foliosConsumed": {
            "type": "integer",
            "format": "int64",
            "description": "Consumo confirmado"
          }
        },
        "required": [
          "operationId",
          "status",
          "uuid",
          "pacCode",
          "createdAtUtc",
          "updatedAtUtc",
          "foliosReserved",
          "foliosConsumed"
        ]
      },
      "Movement": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Identificador UUID",
            "format": "uuid"
          },
          "transactionType": {
            "type": "string",
            "description": "Tipo",
            "enum": [
              "Credit",
              "Adjustment",
              "Reserve",
              "Consume",
              "Release"
            ]
          },
          "quantity": {
            "type": "integer",
            "format": "int64",
            "description": "Cantidad"
          },
          "availableBefore": {
            "type": "integer",
            "format": "int64",
            "description": "Disponible previo"
          },
          "availableAfter": {
            "type": "integer",
            "format": "int64",
            "description": "Disponible posterior"
          },
          "reservedBefore": {
            "type": "integer",
            "format": "int64",
            "description": "Reservado previo"
          },
          "reservedAfter": {
            "type": "integer",
            "format": "int64",
            "description": "Reservado posterior"
          },
          "reference": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAtUtc": {
            "type": "string",
            "description": "Fecha UTC ISO-8601",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "transactionType",
          "quantity",
          "availableBefore",
          "availableAfter",
          "reservedBefore",
          "reservedAfter",
          "reference",
          "createdAtUtc"
        ]
      },
      "OperationPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Operation"
            }
          },
          "page": {
            "type": "integer"
          },
          "pageSize": {
            "type": "integer"
          },
          "totalItems": {
            "type": "integer",
            "format": "int64",
            "description": "Total"
          },
          "totalPages": {
            "type": "integer",
            "format": "int64",
            "description": "Páginas"
          }
        },
        "required": [
          "items",
          "page",
          "pageSize",
          "totalItems",
          "totalPages"
        ]
      },
      "MovementPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Movement"
            }
          },
          "page": {
            "type": "integer"
          },
          "pageSize": {
            "type": "integer"
          },
          "totalItems": {
            "type": "integer",
            "format": "int64",
            "description": "Total"
          },
          "totalPages": {
            "type": "integer",
            "format": "int64",
            "description": "Páginas"
          }
        },
        "required": [
          "items",
          "page",
          "pageSize",
          "totalItems",
          "totalPages"
        ]
      },
      "StampSuccess": {
        "type": "object",
        "properties": {
          "success": {
            "const": true,
            "type": "boolean"
          },
          "operationId": {
            "type": "string",
            "description": "Identificador UUID",
            "format": "uuid"
          },
          "status": {
            "const": "Stamped",
            "type": "string"
          },
          "uuid": {
            "type": "string",
            "description": "Identificador UUID",
            "format": "uuid"
          },
          "stampedXml": {
            "type": "string",
            "description": "XML timbrado sólo en la respuesta inicial, no persistido"
          },
          "foliosConsumed": {
            "const": 1,
            "type": "integer"
          }
        },
        "required": [
          "success",
          "operationId",
          "status",
          "uuid",
          "stampedXml",
          "foliosConsumed"
        ]
      },
      "StampRepeated": {
        "type": "object",
        "properties": {
          "success": {
            "const": true,
            "type": "boolean"
          },
          "operationId": {
            "type": "string",
            "description": "Identificador UUID",
            "format": "uuid"
          },
          "status": {
            "const": "Stamped",
            "type": "string"
          },
          "uuid": {
            "type": "string",
            "description": "Identificador UUID",
            "format": "uuid"
          },
          "foliosConsumed": {
            "const": 1,
            "type": "integer"
          },
          "previouslyConfirmed": {
            "const": true,
            "type": "boolean"
          },
          "xmlAvailable": {
            "const": false,
            "type": "boolean"
          },
          "xmlUnavailableReason": {
            "type": "string",
            "description": "XML no disponible; no se devuelve vacío"
          }
        },
        "required": [
          "success",
          "operationId",
          "status",
          "uuid",
          "foliosConsumed",
          "previouslyConfirmed",
          "xmlAvailable",
          "xmlUnavailableReason"
        ]
      },
      "StampPending": {
        "type": "object",
        "properties": {
          "success": {
            "const": false,
            "type": "boolean"
          },
          "operationId": {
            "type": "string",
            "description": "Identificador UUID",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "description": "Pendiente",
            "enum": [
              "Received",
              "Reserved",
              "Processing",
              "Uncertain"
            ]
          },
          "error": {
            "$ref": "#/components/schemas/PacError"
          },
          "foliosReserved": {
            "type": "integer",
            "minimum": 0,
            "maximum": 1
          }
        },
        "required": [
          "success",
          "operationId",
          "status",
          "error",
          "foliosReserved"
        ]
      },
      "StampRejected": {
        "type": "object",
        "properties": {
          "success": {
            "const": false,
            "type": "boolean"
          },
          "operationId": {
            "type": "string",
            "description": "Identificador UUID",
            "format": "uuid"
          },
          "status": {
            "const": "Rejected",
            "type": "string"
          },
          "error": {
            "$ref": "#/components/schemas/PacError"
          },
          "foliosConsumed": {
            "const": 0,
            "type": "integer"
          },
          "previouslyConfirmed": {
            "type": "boolean"
          }
        },
        "required": [
          "success",
          "operationId",
          "status",
          "error",
          "foliosConsumed"
        ]
      },
      "PersistenceUnconfirmed": {
        "type": "object",
        "properties": {
          "success": {
            "const": false,
            "type": "boolean"
          },
          "operationId": {
            "type": "string",
            "description": "Identificador UUID",
            "format": "uuid"
          },
          "status": {
            "const": "ResolutionPending",
            "type": "string"
          },
          "error": {
            "$ref": "#/components/schemas/PacError"
          },
          "folioState": {
            "const": "Unknown",
            "type": "string"
          }
        },
        "required": [
          "success",
          "operationId",
          "status",
          "error",
          "folioState"
        ]
      },
      "Problem": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "description": "URI del tipo de error"
          },
          "title": {
            "type": "string",
            "description": "Título"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string",
            "description": "Descripción segura"
          },
          "instance": {
            "type": "string",
            "description": "Ruta solicitada"
          },
          "code": {
            "type": "string",
            "description": "Código interno"
          },
          "errors": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "required": []
      }
    }
  }
}