{
  "openapi": "3.1.0",
  "info": {
    "title": "Slaupy API",
    "version": "1.0.0",
    "description": "API de Slaupy. Los errores siguen RFC 9457 (`application/problem+json`) con un `code` estable.\n\n**Versiones.** `/v1` es estable: solo se añaden rutas, campos opcionales y códigos de error nuevos. Un cambio incompatible solo llega en `/v2`, con aviso previo.\n\n**Autenticación.** Con una clave de API de la organización: `Authorization: Bearer slk_live_…` (o `slk_test_…` en una organización de pruebas). La clave solo lee salvo los alcances de escritura que se le den, y nunca llega a miembros, plan, ajustes ni certificados.\n\n**Idempotencia.** Las escrituras admiten `Idempotency-Key` (8 a 255 caracteres, 24 h): repetir la petición con la misma clave y el mismo cuerpo devuelve la respuesta guardada con `Idempotent-Replayed: true`. Emitir y anular facturas la exigen; crear claves o secretos la ignora (su respuesta no se guarda).\n\n**Límites.** Cada clave tiene su cupo por minuto (`RateLimit-*`); al agotarlo, 429 con `Retry-After`."
  },
  "tags": [
    {
      "name": "orgs"
    },
    {
      "name": "files"
    },
    {
      "name": "contacts"
    },
    {
      "name": "products"
    },
    {
      "name": "series"
    },
    {
      "name": "invoices"
    },
    {
      "name": "payments"
    },
    {
      "name": "delivery-notes"
    },
    {
      "name": "document-styles"
    },
    {
      "name": "recurring"
    },
    {
      "name": "quotes"
    },
    {
      "name": "purchases"
    },
    {
      "name": "payment-batches"
    },
    {
      "name": "inbox"
    },
    {
      "name": "assets"
    },
    {
      "name": "ai"
    },
    {
      "name": "tax"
    },
    {
      "name": "accounting"
    },
    {
      "name": "approvals"
    },
    {
      "name": "import"
    },
    {
      "name": "sales-channels"
    },
    {
      "name": "bank"
    },
    {
      "name": "verifactu"
    },
    {
      "name": "billing"
    },
    {
      "name": "search"
    },
    {
      "name": "organizations"
    },
    {
      "name": "webhooks"
    },
    {
      "name": "receivables"
    },
    {
      "name": "close"
    },
    {
      "name": "treasury"
    }
  ],
  "paths": {
    "/v1/orgs/{orgId}": {
      "get": {
        "operationId": "getOrganization",
        "tags": [
          "orgs"
        ],
        "summary": "Datos de la organización",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "org:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Organización",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MyOrganization"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax-profile": {
      "get": {
        "operationId": "getTaxProfile",
        "tags": [
          "orgs"
        ],
        "summary": "Datos fiscales de la organización (los que van en las facturas)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "org:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Datos fiscales",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TaxProfile"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/onboarding": {
      "get": {
        "operationId": "getOnboarding",
        "tags": [
          "orgs"
        ],
        "summary": "Por dónde va el alta guiada (pasos hechos y saltados)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "org:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Estado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Onboarding"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/files": {
      "post": {
        "operationId": "createFileUpload",
        "tags": [
          "files"
        ],
        "summary": "Pedir una URL firmada para subir un fichero directamente al almacenamiento",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "files:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateFile"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Sube el fichero con PUT a uploadUrl con exactamente estas cabeceras",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "file": {
                      "$ref": "#/components/schemas/File"
                    },
                    "uploadUrl": {
                      "type": "string",
                      "format": "uri"
                    },
                    "uploadHeaders": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "string"
                      }
                    },
                    "expiresAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "file",
                    "uploadUrl",
                    "uploadHeaders",
                    "expiresAt"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/files/{fileId}/complete": {
      "post": {
        "operationId": "completeFileUpload",
        "tags": [
          "files"
        ],
        "summary": "Confirmar la subida: se comprueban tamaño, tipo real y SHA-256",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "files:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "fileId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Listo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/File"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/files/{fileId}": {
      "get": {
        "operationId": "getFile",
        "tags": [
          "files"
        ],
        "summary": "Datos de un fichero",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "files:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "fileId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Fichero",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/File"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/files/{fileId}/download": {
      "get": {
        "operationId": "downloadFile",
        "tags": [
          "files"
        ],
        "summary": "URL firmada de descarga, válida 5 minutos (la descarga queda auditada)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "files:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "fileId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "URL de descarga",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "expiresAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "url",
                    "expiresAt"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/contacts": {
      "get": {
        "operationId": "listContacts",
        "tags": [
          "contacts"
        ],
        "summary": "Clientes y proveedores, por nombre, con búsqueda y paginación por cursor",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            },
            "required": false,
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 512,
              "pattern": "^[A-Za-z0-9_-]+$"
            },
            "required": false,
            "name": "cursor",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "Busca en nombre, nombre comercial y NIF"
            },
            "required": false,
            "description": "Busca en nombre, nombre comercial y NIF",
            "name": "q",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "customer",
                "supplier"
              ]
            },
            "required": false,
            "name": "role",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "false",
                "true",
                "all"
              ],
              "default": "false"
            },
            "required": false,
            "name": "archived",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Página",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactPage"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createContact",
        "tags": [
          "contacts"
        ],
        "summary": "Alta de un cliente o proveedor",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "company",
                      "individual"
                    ],
                    "default": "company"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "tradeName": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 120,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "isCustomer": {
                    "type": "boolean",
                    "default": true
                  },
                  "isSupplier": {
                    "type": "boolean",
                    "default": false
                  },
                  "taxIdType": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "nif",
                      "vat_eu",
                      "passport",
                      "foreign_id",
                      "residence_cert",
                      "other",
                      null
                    ]
                  },
                  "taxId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 20
                  },
                  "taxIdCountry": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "email": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 254
                  },
                  "phone": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 32,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "line1": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 200,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "line2": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 200,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "postalCode": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 16,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "city": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 120,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "province": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 120,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "addressCountry": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "paymentTermsDays": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0,
                    "maximum": 365
                  },
                  "supplierIban": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 42
                  },
                  "defaultWithholdingRate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "equivalenceSurcharge": {
                    "type": "boolean",
                    "default": false
                  },
                  "rentalProperty": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "properties": {
                      "cadastralRef": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "pattern": "^[0-9A-Z]{14}(?:[0-9A-Z]{6})?$"
                      },
                      "situation": {
                        "type": "string",
                        "enum": [
                          "1",
                          "2",
                          "3",
                          "4"
                        ]
                      },
                      "address": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 200,
                        "pattern": "^[^\\p{Cc}]*$/u"
                      },
                      "postalCode": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "pattern": "^\\d{5}$"
                      },
                      "municipality": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "maxLength": 120,
                        "pattern": "^[^\\p{Cc}]*$/u"
                      }
                    },
                    "required": [
                      "cadastralRef",
                      "situation",
                      "address",
                      "postalCode"
                    ],
                    "additionalProperties": false
                  },
                  "documentLocale": {
                    "type": "string",
                    "enum": [
                      "es",
                      "en"
                    ],
                    "default": "es"
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  }
                },
                "required": [
                  "name"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ya existía con ese id (reintento)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Contact"
                }
              }
            }
          },
          "201": {
            "description": "Creado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Contact"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/contacts/duplicates": {
      "get": {
        "operationId": "findContactDuplicates",
        "tags": [
          "contacts"
        ],
        "summary": "Contactos con el mismo identificador fiscal (aviso, no impide guardar)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 20
            },
            "required": true,
            "name": "taxId",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "excludeId",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Posibles duplicados",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "name": {
                            "type": "string"
                          },
                          "archived": {
                            "type": "boolean"
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "archived"
                        ]
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/contacts/{contactId}": {
      "get": {
        "operationId": "getContact",
        "tags": [
          "contacts"
        ],
        "summary": "Un contacto",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "contactId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Contacto",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Contact"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateContact",
        "tags": [
          "contacts"
        ],
        "summary": "Editar un contacto (con la versión leída). Las facturas emitidas no cambian",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "contactId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "company",
                      "individual"
                    ]
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "tradeName": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 120,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "isCustomer": {
                    "type": "boolean"
                  },
                  "isSupplier": {
                    "type": "boolean"
                  },
                  "taxIdType": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "nif",
                      "vat_eu",
                      "passport",
                      "foreign_id",
                      "residence_cert",
                      "other",
                      null
                    ]
                  },
                  "taxId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 20
                  },
                  "taxIdCountry": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "email": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 254
                  },
                  "phone": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 32,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "line1": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 200,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "line2": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 200,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "postalCode": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 16,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "city": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 120,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "province": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 120,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "addressCountry": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "paymentTermsDays": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0,
                    "maximum": 365
                  },
                  "supplierIban": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 42
                  },
                  "defaultWithholdingRate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "equivalenceSurcharge": {
                    "type": "boolean"
                  },
                  "rentalProperty": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "properties": {
                      "cadastralRef": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "pattern": "^[0-9A-Z]{14}(?:[0-9A-Z]{6})?$"
                      },
                      "situation": {
                        "type": "string",
                        "enum": [
                          "1",
                          "2",
                          "3",
                          "4"
                        ]
                      },
                      "address": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 200,
                        "pattern": "^[^\\p{Cc}]*$/u"
                      },
                      "postalCode": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "pattern": "^\\d{5}$"
                      },
                      "municipality": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "maxLength": 120,
                        "pattern": "^[^\\p{Cc}]*$/u"
                      }
                    },
                    "required": [
                      "cadastralRef",
                      "situation",
                      "address",
                      "postalCode"
                    ],
                    "additionalProperties": false
                  },
                  "documentLocale": {
                    "type": "string",
                    "enum": [
                      "es",
                      "en"
                    ]
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Guardado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Contact"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteContact",
        "tags": [
          "contacts"
        ],
        "summary": "Borrar un contacto sin documentos (si tiene, se archiva en su lugar: 409 contact_in_use)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "contactId",
            "in": "path"
          }
        ],
        "responses": {
          "204": {
            "description": "Borrado"
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/contacts/{contactId}/archive": {
      "post": {
        "operationId": "archiveContact",
        "tags": [
          "contacts"
        ],
        "summary": "Archivar: deja de ofrecerse al facturar, pero conserva su historial",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "contactId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Archivado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Contact"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/contacts/{contactId}/unarchive": {
      "post": {
        "operationId": "unarchiveContact",
        "tags": [
          "contacts"
        ],
        "summary": "Recuperar un contacto archivado",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "contactId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Activo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Contact"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/contacts/{contactId}/verify-vat": {
      "post": {
        "operationId": "verifyContactVat",
        "tags": [
          "contacts"
        ],
        "summary": "Comprobar el NIF-IVA del contacto en VIES (Comisión Europea). Si el servicio no responde, «no disponible»: no bloquea nada",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "contactId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Resultado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ViesCheck"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/products": {
      "get": {
        "operationId": "listProducts",
        "tags": [
          "products"
        ],
        "summary": "Productos y servicios, por nombre, con búsqueda y paginación por cursor",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            },
            "required": false,
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 512,
              "pattern": "^[A-Za-z0-9_-]+$"
            },
            "required": false,
            "name": "cursor",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 100
            },
            "required": false,
            "name": "q",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "false",
                "true",
                "all"
              ],
              "default": "false"
            },
            "required": false,
            "name": "archived",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Página",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProductPage"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createProduct",
        "tags": [
          "products"
        ],
        "summary": "Alta de un producto o servicio",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 1000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "good",
                      "service"
                    ],
                    "default": "service"
                  },
                  "unitPrice": {
                    "type": "string"
                  },
                  "taxCode": {
                    "type": "string",
                    "default": "IVA21"
                  },
                  "unit": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 20,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "sku": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 64,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  }
                },
                "required": [
                  "name",
                  "unitPrice"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ya existía con ese id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Product"
                }
              }
            }
          },
          "201": {
            "description": "Creado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Product"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/products/{productId}": {
      "get": {
        "operationId": "getProduct",
        "tags": [
          "products"
        ],
        "summary": "Un producto",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "productId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Producto",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Product"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateProduct",
        "tags": [
          "products"
        ],
        "summary": "Editar un producto (no cambia las facturas que ya lo usan)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "productId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 1000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "good",
                      "service"
                    ]
                  },
                  "unitPrice": {
                    "type": "string"
                  },
                  "taxCode": {
                    "type": "string"
                  },
                  "unit": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 20,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "sku": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 64,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Guardado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Product"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteProduct",
        "tags": [
          "products"
        ],
        "summary": "Borrar un producto que ninguna línea usa",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "productId",
            "in": "path"
          }
        ],
        "responses": {
          "204": {
            "description": "Borrado"
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/products/{productId}/archive": {
      "post": {
        "operationId": "archiveProduct",
        "tags": [
          "products"
        ],
        "summary": "Archivar un producto",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "productId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Archivado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Product"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/products/{productId}/unarchive": {
      "post": {
        "operationId": "unarchiveProduct",
        "tags": [
          "products"
        ],
        "summary": "Recuperar un producto archivado",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "productId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Activo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Product"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/series": {
      "get": {
        "operationId": "listSeries",
        "tags": [
          "series"
        ],
        "summary": "Series de facturación con el próximo número de cada una",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Series",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/InvoiceSeries"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/invoices": {
      "get": {
        "operationId": "listInvoices",
        "tags": [
          "invoices"
        ],
        "summary": "Facturas (más recientes primero) con filtros, paginación por cursor y totales del filtro",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            },
            "required": false,
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 512,
              "pattern": "^[A-Za-z0-9_-]+$"
            },
            "required": false,
            "name": "cursor",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "issued",
                "voided"
              ]
            },
            "required": false,
            "name": "status",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "F1",
                "F2",
                "F3",
                "R1",
                "R2",
                "R3",
                "R4",
                "R5"
              ]
            },
            "required": false,
            "name": "type",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "contactId",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "seriesId",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "unpaid",
                "partial",
                "paid",
                "overdue",
                "pending"
              ],
              "description": "`overdue`: por cobrar y vencida. `pending`: por cobrar y aún no vencida (el estado «Emitida» de la lista)."
            },
            "required": false,
            "description": "`overdue`: por cobrar y vencida. `pending`: por cobrar y aún no vencida (el estado «Emitida» de la lista).",
            "name": "paymentStatus",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 32
            },
            "required": false,
            "name": "vfStatus",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "from",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "to",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "Número o nombre del cliente"
            },
            "required": false,
            "description": "Número o nombre del cliente",
            "name": "q",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Página",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvoicePage"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createInvoiceDraft",
        "tags": [
          "invoices"
        ],
        "summary": "Crear un borrador. No tiene número: se numera al emitir",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "F1",
                      "F2",
                      "F3",
                      "R1",
                      "R2",
                      "R3",
                      "R4",
                      "R5"
                    ],
                    "default": "F1"
                  },
                  "seriesId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "contactId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "issueDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "operationDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "dueDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 500,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  },
                  "paymentMethod": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "transfer",
                      "card",
                      "cash",
                      "direct_debit",
                      "bizum",
                      "other",
                      null
                    ]
                  },
                  "paymentDetails": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 200,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "documentLocale": {
                    "type": "string",
                    "enum": [
                      "es",
                      "en"
                    ]
                  },
                  "globalDiscountPct": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "deliveryCountry": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "productId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 1000,
                          "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                        },
                        "quantity": {
                          "type": "string"
                        },
                        "unitPrice": {
                          "type": "string"
                        },
                        "discountPct": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "taxCode": {
                          "type": "string"
                        },
                        "exemptionCause": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "enum": [
                            "E1",
                            "E2",
                            "E3",
                            "E4",
                            "E5",
                            "E6",
                            null
                          ]
                        },
                        "withholdingRate": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "unit": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 20,
                          "pattern": "^[^\\p{Cc}]*$/u"
                        }
                      },
                      "required": [
                        "quantity",
                        "unitPrice",
                        "taxCode"
                      ],
                      "additionalProperties": false
                    },
                    "maxItems": 500,
                    "default": []
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ya existía con ese id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Invoice"
                }
              }
            }
          },
          "201": {
            "description": "Borrador",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Invoice"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/invoices/{invoiceId}": {
      "get": {
        "operationId": "getInvoice",
        "tags": [
          "invoices"
        ],
        "summary": "Una factura con sus líneas y su desglose",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Factura",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Invoice"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateInvoiceDraft",
        "tags": [
          "invoices"
        ],
        "summary": "Editar un borrador (con la versión leída). Una factura emitida no se edita: 409 invoice_not_draft",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "F1",
                      "F2",
                      "F3",
                      "R1",
                      "R2",
                      "R3",
                      "R4",
                      "R5"
                    ]
                  },
                  "seriesId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "contactId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "issueDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "operationDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "dueDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 500,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  },
                  "paymentMethod": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "transfer",
                      "card",
                      "cash",
                      "direct_debit",
                      "bizum",
                      "other",
                      null
                    ]
                  },
                  "paymentDetails": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 200,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "documentLocale": {
                    "type": "string",
                    "enum": [
                      "es",
                      "en"
                    ]
                  },
                  "globalDiscountPct": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "deliveryCountry": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "productId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 1000,
                          "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                        },
                        "quantity": {
                          "type": "string"
                        },
                        "unitPrice": {
                          "type": "string"
                        },
                        "discountPct": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "taxCode": {
                          "type": "string"
                        },
                        "exemptionCause": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "enum": [
                            "E1",
                            "E2",
                            "E3",
                            "E4",
                            "E5",
                            "E6",
                            null
                          ]
                        },
                        "withholdingRate": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "unit": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 20,
                          "pattern": "^[^\\p{Cc}]*$/u"
                        }
                      },
                      "required": [
                        "quantity",
                        "unitPrice",
                        "taxCode"
                      ],
                      "additionalProperties": false
                    },
                    "maxItems": 500
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Guardado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Invoice"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteInvoiceDraft",
        "tags": [
          "invoices"
        ],
        "summary": "Borrar un borrador. Lo emitido no se borra nunca",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          }
        ],
        "responses": {
          "204": {
            "description": "Borrado"
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/invoices/preview-totals": {
      "post": {
        "operationId": "previewInvoiceTotals",
        "tags": [
          "invoices"
        ],
        "summary": "Calcular totales sin guardar (el mismo cálculo que al guardar)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "contactId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "issueDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "operationDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "globalDiscountPct": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "productId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 1000,
                          "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                        },
                        "quantity": {
                          "type": "string"
                        },
                        "unitPrice": {
                          "type": "string"
                        },
                        "discountPct": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "taxCode": {
                          "type": "string"
                        },
                        "exemptionCause": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "enum": [
                            "E1",
                            "E2",
                            "E3",
                            "E4",
                            "E5",
                            "E6",
                            null
                          ]
                        },
                        "withholdingRate": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "unit": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 20,
                          "pattern": "^[^\\p{Cc}]*$/u"
                        }
                      },
                      "required": [
                        "quantity",
                        "unitPrice",
                        "taxCode"
                      ],
                      "additionalProperties": false
                    },
                    "maxItems": 500
                  }
                },
                "required": [
                  "lines"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Totales",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvoiceTotalsPreview"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/invoices/{invoiceId}/issue": {
      "post": {
        "operationId": "issueInvoice",
        "tags": [
          "invoices"
        ],
        "summary": "Emitir: numera, congela emisor y cliente y encadena el registro VERI*FACTU en una sola transacción. Exige Idempotency-Key",
        "x-idempotency": "required",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:issue",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IssueInvoice"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Emitida",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Invoice"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "428": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/invoices/{invoiceId}/rectify": {
      "post": {
        "operationId": "rectifyInvoice",
        "tags": [
          "invoices"
        ],
        "summary": "Crear el borrador de una rectificativa (por diferencias o por sustitución) en la serie rectificativa. Se emite con /issue",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RectifyInvoice"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Borrador de rectificativa",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Invoice"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/invoices/{invoiceId}/void": {
      "post": {
        "operationId": "voidInvoice",
        "tags": [
          "invoices"
        ],
        "summary": "Anular una factura que no debió emitirse: registro de anulación encadenado. El número no se libera. Exige Idempotency-Key",
        "x-idempotency": "required",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:void",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VoidInvoice"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Anulada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Invoice"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "428": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/invoices/{invoiceId}/payments": {
      "get": {
        "operationId": "listInvoicePayments",
        "tags": [
          "payments"
        ],
        "summary": "Cobros de una factura, con lo pendiente",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Cobros",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvoicePayments"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createInvoicePayment",
        "tags": [
          "payments"
        ],
        "summary": "Registrar un cobro parcial o total (nunca más de lo pendiente)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "paidOn": {
                    "type": "string"
                  },
                  "amountMinor": {
                    "type": "integer"
                  },
                  "method": {
                    "type": "string",
                    "enum": [
                      "transfer",
                      "card",
                      "cash",
                      "direct_debit",
                      "bizum",
                      "other"
                    ],
                    "default": "transfer"
                  },
                  "reference": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 120,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 500,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  }
                },
                "required": [
                  "paidOn",
                  "amountMinor"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Registrado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvoicePayments"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/invoices/{invoiceId}/payments/{paymentId}": {
      "patch": {
        "operationId": "updateInvoicePayment",
        "tags": [
          "payments"
        ],
        "summary": "Corregir un cobro (con la versión leída)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "paymentId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "paidOn": {
                    "type": "string"
                  },
                  "amountMinor": {
                    "type": "integer"
                  },
                  "method": {
                    "type": "string",
                    "enum": [
                      "transfer",
                      "card",
                      "cash",
                      "direct_debit",
                      "bizum",
                      "other"
                    ]
                  },
                  "reference": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 120,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 500,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Guardado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvoicePayments"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteInvoicePayment",
        "tags": [
          "payments"
        ],
        "summary": "Borrar un cobro",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "paymentId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Borrado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvoicePayments"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/invoices/{invoiceId}/pdf": {
      "get": {
        "operationId": "getInvoicePdf",
        "tags": [
          "invoices"
        ],
        "summary": "PDF de la factura. Un borrador sale con la marca BORRADOR; una anulada, con ANULADA",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/delivery-notes": {
      "get": {
        "operationId": "listDeliveryNotes",
        "tags": [
          "delivery-notes"
        ],
        "summary": "Albaranes, más recientes primero",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            },
            "required": false,
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 512,
              "pattern": "^[A-Za-z0-9_-]+$"
            },
            "required": false,
            "name": "cursor",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "delivered",
                "invoiced",
                "cancelled"
              ]
            },
            "required": false,
            "name": "status",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "contactId",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Página",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeliveryNotePage"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createDeliveryNote",
        "tags": [
          "delivery-notes"
        ],
        "summary": "Crear un albarán, desde cero o desde un presupuesto aceptado",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "quoteId": {
                    "type": "string"
                  },
                  "contactId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "deliveryDate": {
                    "type": "string"
                  },
                  "valued": {
                    "type": "boolean",
                    "default": true
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  },
                  "documentLocale": {
                    "type": "string",
                    "enum": [
                      "es",
                      "en"
                    ]
                  },
                  "deliveryCountry": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "productId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 1000,
                          "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                        },
                        "quantity": {
                          "type": "string"
                        },
                        "unitPrice": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "discountPct": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "taxCode": {
                          "type": "string"
                        },
                        "exemptionCause": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "enum": [
                            "E1",
                            "E2",
                            "E3",
                            "E4",
                            "E5",
                            "E6",
                            null
                          ]
                        },
                        "withholdingRate": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "unit": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 20,
                          "pattern": "^[^\\p{Cc}]*$/u"
                        }
                      },
                      "required": [
                        "quantity",
                        "taxCode"
                      ],
                      "additionalProperties": false
                    },
                    "maxItems": 500,
                    "default": []
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ya existía",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeliveryNote"
                }
              }
            }
          },
          "201": {
            "description": "Creado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeliveryNote"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/delivery-notes/{noteId}": {
      "get": {
        "operationId": "getDeliveryNote",
        "tags": [
          "delivery-notes"
        ],
        "summary": "Un albarán",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "noteId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Albarán",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeliveryNote"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateDeliveryNote",
        "tags": [
          "delivery-notes"
        ],
        "summary": "Editar un albarán no facturado",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "noteId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "contactId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "deliveryDate": {
                    "type": "string"
                  },
                  "valued": {
                    "type": "boolean"
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  },
                  "documentLocale": {
                    "type": "string",
                    "enum": [
                      "es",
                      "en"
                    ]
                  },
                  "deliveryCountry": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "productId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 1000,
                          "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                        },
                        "quantity": {
                          "type": "string"
                        },
                        "unitPrice": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "discountPct": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "taxCode": {
                          "type": "string"
                        },
                        "exemptionCause": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "enum": [
                            "E1",
                            "E2",
                            "E3",
                            "E4",
                            "E5",
                            "E6",
                            null
                          ]
                        },
                        "withholdingRate": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "unit": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 20,
                          "pattern": "^[^\\p{Cc}]*$/u"
                        }
                      },
                      "required": [
                        "quantity",
                        "taxCode"
                      ],
                      "additionalProperties": false
                    },
                    "maxItems": 500
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Guardado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeliveryNote"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/delivery-notes/{noteId}/status": {
      "post": {
        "operationId": "setDeliveryNoteStatus",
        "tags": [
          "delivery-notes"
        ],
        "summary": "Marcar como entregado o cancelado",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "noteId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "delivered",
                      "cancelled",
                      "draft"
                    ]
                  }
                },
                "required": [
                  "version",
                  "status"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cambiado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeliveryNote"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/delivery-notes/{noteId}/invoice": {
      "post": {
        "operationId": "invoiceDeliveryNote",
        "tags": [
          "delivery-notes"
        ],
        "summary": "Facturar un albarán entregado: crea un borrador de factura",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "noteId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Borrador creado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeliveryNotesInvoiced"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/delivery-notes/invoice-batch": {
      "post": {
        "operationId": "invoiceDeliveryNotes",
        "tags": [
          "delivery-notes"
        ],
        "summary": "Facturar varios albaranes del mismo cliente en un solo borrador de factura",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "minItems": 1,
                    "maxItems": 100
                  }
                },
                "required": [
                  "ids"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Borrador creado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeliveryNotesInvoiced"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/delivery-notes/{noteId}/pdf": {
      "get": {
        "operationId": "getDeliveryNotePdf",
        "tags": [
          "delivery-notes"
        ],
        "summary": "PDF del albarán, valorado o sin valorar",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "noteId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/document-styles": {
      "get": {
        "operationId": "getDocumentStyles",
        "tags": [
          "document-styles"
        ],
        "summary": "Estilo de los documentos: el de la organización, los de cada serie y el logotipo",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Estilos",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentStyles"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/document-styles/logo": {
      "get": {
        "operationId": "getDocumentLogo",
        "tags": [
          "document-styles"
        ],
        "summary": "El logotipo procesado, como data URI PNG, para mostrarlo en la interfaz",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Logotipo",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "dataUri": {
                      "type": "string"
                    },
                    "width": {
                      "type": "integer"
                    },
                    "height": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "dataUri",
                    "width",
                    "height"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/recurring-invoices": {
      "get": {
        "operationId": "listRecurringInvoices",
        "tags": [
          "recurring"
        ],
        "summary": "Facturas recurrentes, por próxima fecha",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Plantillas",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/RecurringInvoice"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createRecurringInvoice",
        "tags": [
          "recurring"
        ],
        "summary": "Crear una factura recurrente. La emisión automática exige confirmarla y el permiso de emitir",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "contactId": {
                    "type": "string"
                  },
                  "seriesId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "frequency": {
                    "type": "string",
                    "enum": [
                      "weekly",
                      "monthly",
                      "quarterly",
                      "yearly"
                    ]
                  },
                  "dayOfMonth": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 1,
                    "maximum": 31,
                    "default": null
                  },
                  "nextDate": {
                    "type": "string"
                  },
                  "endDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "draft",
                      "issue"
                    ],
                    "default": "draft"
                  },
                  "sendEmail": {
                    "type": "boolean",
                    "default": false
                  },
                  "confirmAutoIssue": {
                    "type": "boolean",
                    "default": false
                  },
                  "active": {
                    "type": "boolean",
                    "default": true
                  },
                  "paymentMethod": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "transfer",
                      "card",
                      "cash",
                      "direct_debit",
                      "bizum",
                      "other",
                      null
                    ]
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  },
                  "deliveryCountry": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "productId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 1000,
                          "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                        },
                        "quantity": {
                          "type": "string"
                        },
                        "unitPrice": {
                          "type": "string"
                        },
                        "discountPct": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "taxCode": {
                          "type": "string"
                        },
                        "exemptionCause": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "enum": [
                            "E1",
                            "E2",
                            "E3",
                            "E4",
                            "E5",
                            "E6",
                            null
                          ]
                        },
                        "withholdingRate": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "unit": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 20,
                          "pattern": "^[^\\p{Cc}]*$/u"
                        }
                      },
                      "required": [
                        "quantity",
                        "unitPrice",
                        "taxCode"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 500
                  }
                },
                "required": [
                  "name",
                  "contactId",
                  "frequency",
                  "nextDate",
                  "lines"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Creada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecurringInvoice"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/recurring-invoices/{recurringId}": {
      "get": {
        "operationId": "getRecurringInvoice",
        "tags": [
          "recurring"
        ],
        "summary": "Una factura recurrente con sus últimas ejecuciones",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "recurringId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Plantilla",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecurringInvoice"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateRecurringInvoice",
        "tags": [
          "recurring"
        ],
        "summary": "Editar una factura recurrente (con la versión leída)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "recurringId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "contactId": {
                    "type": "string"
                  },
                  "seriesId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "frequency": {
                    "type": "string",
                    "enum": [
                      "weekly",
                      "monthly",
                      "quarterly",
                      "yearly"
                    ]
                  },
                  "dayOfMonth": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 1,
                    "maximum": 31
                  },
                  "nextDate": {
                    "type": "string"
                  },
                  "endDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "draft",
                      "issue"
                    ]
                  },
                  "sendEmail": {
                    "type": "boolean"
                  },
                  "confirmAutoIssue": {
                    "type": "boolean"
                  },
                  "active": {
                    "type": "boolean"
                  },
                  "paymentMethod": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "transfer",
                      "card",
                      "cash",
                      "direct_debit",
                      "bizum",
                      "other",
                      null
                    ]
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  },
                  "deliveryCountry": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "productId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 1000,
                          "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                        },
                        "quantity": {
                          "type": "string"
                        },
                        "unitPrice": {
                          "type": "string"
                        },
                        "discountPct": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "taxCode": {
                          "type": "string"
                        },
                        "exemptionCause": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "enum": [
                            "E1",
                            "E2",
                            "E3",
                            "E4",
                            "E5",
                            "E6",
                            null
                          ]
                        },
                        "withholdingRate": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "unit": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 20,
                          "pattern": "^[^\\p{Cc}]*$/u"
                        }
                      },
                      "required": [
                        "quantity",
                        "unitPrice",
                        "taxCode"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 500
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Guardada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecurringInvoice"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteRecurringInvoice",
        "tags": [
          "recurring"
        ],
        "summary": "Borrar una factura recurrente (las facturas que ya creó se quedan)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "recurringId",
            "in": "path"
          }
        ],
        "responses": {
          "204": {
            "description": "Borrada"
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/quotes": {
      "get": {
        "operationId": "listQuotes",
        "tags": [
          "quotes"
        ],
        "summary": "Presupuestos y proformas, más recientes primero",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            },
            "required": false,
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 512,
              "pattern": "^[A-Za-z0-9_-]+$"
            },
            "required": false,
            "name": "cursor",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "sent",
                "accepted",
                "rejected",
                "invoiced"
              ]
            },
            "required": false,
            "name": "status",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "contactId",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Página",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuotePage"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createQuote",
        "tags": [
          "quotes"
        ],
        "summary": "Crear un presupuesto o una proforma (numerados al crearse; sin valor fiscal)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "quote",
                      "proforma"
                    ],
                    "default": "quote"
                  },
                  "contactId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "issueDate": {
                    "type": "string"
                  },
                  "validUntil": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  },
                  "documentLocale": {
                    "type": "string",
                    "enum": [
                      "es",
                      "en"
                    ]
                  },
                  "globalDiscountPct": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "deliveryCountry": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "productId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 1000,
                          "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                        },
                        "quantity": {
                          "type": "string"
                        },
                        "unitPrice": {
                          "type": "string"
                        },
                        "discountPct": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "taxCode": {
                          "type": "string"
                        },
                        "exemptionCause": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "enum": [
                            "E1",
                            "E2",
                            "E3",
                            "E4",
                            "E5",
                            "E6",
                            null
                          ]
                        },
                        "withholdingRate": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "unit": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 20,
                          "pattern": "^[^\\p{Cc}]*$/u"
                        }
                      },
                      "required": [
                        "quantity",
                        "unitPrice",
                        "taxCode"
                      ],
                      "additionalProperties": false
                    },
                    "maxItems": 500,
                    "default": []
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ya existía con ese id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "201": {
            "description": "Creado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/quotes/{quoteId}": {
      "get": {
        "operationId": "getQuote",
        "tags": [
          "quotes"
        ],
        "summary": "Un presupuesto",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "quoteId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Presupuesto",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateQuote",
        "tags": [
          "quotes"
        ],
        "summary": "Editar un presupuesto que no se ha aceptado ni facturado",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "quoteId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "contactId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "issueDate": {
                    "type": "string"
                  },
                  "validUntil": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  },
                  "documentLocale": {
                    "type": "string",
                    "enum": [
                      "es",
                      "en"
                    ]
                  },
                  "globalDiscountPct": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "deliveryCountry": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "productId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 1000,
                          "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                        },
                        "quantity": {
                          "type": "string"
                        },
                        "unitPrice": {
                          "type": "string"
                        },
                        "discountPct": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "taxCode": {
                          "type": "string"
                        },
                        "exemptionCause": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "enum": [
                            "E1",
                            "E2",
                            "E3",
                            "E4",
                            "E5",
                            "E6",
                            null
                          ]
                        },
                        "withholdingRate": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "unit": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 20,
                          "pattern": "^[^\\p{Cc}]*$/u"
                        }
                      },
                      "required": [
                        "quantity",
                        "unitPrice",
                        "taxCode"
                      ],
                      "additionalProperties": false
                    },
                    "maxItems": 500
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Guardado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteQuote",
        "tags": [
          "quotes"
        ],
        "summary": "Borrar un presupuesto en borrador",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "quoteId",
            "in": "path"
          }
        ],
        "responses": {
          "204": {
            "description": "Borrado"
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/quotes/{quoteId}/status": {
      "post": {
        "operationId": "setQuoteStatus",
        "tags": [
          "quotes"
        ],
        "summary": "Marcar como enviado, aceptado o rechazado",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "quoteId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "sent",
                      "accepted",
                      "rejected"
                    ]
                  }
                },
                "required": [
                  "version",
                  "status"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cambiado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/quotes/{quoteId}/convert": {
      "post": {
        "operationId": "convertQuote",
        "tags": [
          "quotes"
        ],
        "summary": "Convertir en un borrador de factura con las mismas líneas y cliente",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "quoteId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Borrador de factura",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "invoiceId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "quote": {
                      "$ref": "#/components/schemas/Quote"
                    }
                  },
                  "required": [
                    "invoiceId",
                    "quote"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/quotes/{quoteId}/public-link": {
      "post": {
        "operationId": "createQuotePublicLink",
        "tags": [
          "quotes"
        ],
        "summary": "Enlace firmado para que el cliente acepte o rechace el presupuesto sin cuenta",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "quoteId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "days": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 90,
                    "default": 30
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Enlace",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "expiresAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "url",
                    "expiresAt"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/quotes/{quoteId}/pdf": {
      "get": {
        "operationId": "getQuotePdf",
        "tags": [
          "quotes"
        ],
        "summary": "PDF del presupuesto, que dice bien visible que no es una factura",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "quoteId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/invoices/{invoiceId}/send": {
      "post": {
        "operationId": "sendInvoice",
        "tags": [
          "invoices"
        ],
        "summary": "Enviar la factura por correo con el PDF adjunto y, si se pide, un enlace público de descarga que caduca",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SendInvoice"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "En la cola de envío",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvoiceSent"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/invoices/{invoiceId}/deliveries": {
      "get": {
        "operationId": "listInvoiceDeliveries",
        "tags": [
          "invoices"
        ],
        "summary": "Historial de envíos de una factura",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Envíos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/InvoiceDelivery"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/expense-categories": {
      "get": {
        "operationId": "listExpenseCategories",
        "tags": [
          "purchases"
        ],
        "summary": "Categorías de gasto: las de sistema (con su concepto fiscal) y las propias",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Categorías",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ExpenseCategory"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createExpenseCategory",
        "tags": [
          "purchases"
        ],
        "summary": "Crear una categoría propia que cuelga de una de sistema",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "parentCode": {
                    "type": "string",
                    "pattern": "^[a-z_]{2,40}$"
                  },
                  "vatDeductiblePct": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "irpfDeductiblePct": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "name",
                  "parentCode"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Creada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExpenseCategory"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/expense-categories/{categoryId}": {
      "patch": {
        "operationId": "updateExpenseCategory",
        "tags": [
          "purchases"
        ],
        "summary": "Editar una categoría propia",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "categoryId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "parentCode": {
                    "type": "string",
                    "pattern": "^[a-z_]{2,40}$"
                  },
                  "vatDeductiblePct": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "irpfDeductiblePct": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Guardada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExpenseCategory"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/expense-categories/{categoryId}/archive": {
      "post": {
        "operationId": "archiveExpenseCategory",
        "tags": [
          "purchases"
        ],
        "summary": "Archivar una categoría propia (los documentos que la usan no cambian)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "categoryId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Archivada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExpenseCategory"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/purchases/payables": {
      "get": {
        "operationId": "getPayables",
        "tags": [
          "purchases"
        ],
        "summary": "«Por pagar»: compras confirmadas pendientes por vencimiento (vencidas, esta semana, este mes, después)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Pendiente de pago",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Payables"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/purchases/preview-totals": {
      "post": {
        "operationId": "previewPurchaseTotals",
        "tags": [
          "purchases"
        ],
        "summary": "Calcular cuotas, parte deducible y no deducible sin guardar nada",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "documentKind": {
                    "type": "string",
                    "enum": [
                      "invoice",
                      "simplified",
                      "other"
                    ]
                  },
                  "operationKind": {
                    "type": "string",
                    "enum": [
                      "domestic",
                      "intra_goods",
                      "intra_services",
                      "import",
                      "reverse_charge_domestic",
                      "not_subject"
                    ],
                    "default": "domestic"
                  },
                  "contactId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid"
                  },
                  "supplierName": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 200,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "supplierTaxId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 30,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "number": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 60,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "issueDate": {
                    "type": "string"
                  },
                  "operationDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "registrationDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "dueDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "paymentMethod": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "transfer",
                      "card",
                      "cash",
                      "direct_debit",
                      "bizum",
                      "other",
                      null
                    ]
                  },
                  "qualifiedSimplified": {
                    "type": "boolean",
                    "default": false
                  },
                  "supplierCashAccounting": {
                    "type": "boolean",
                    "default": false
                  },
                  "withholdingKind": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "professional",
                      "rental",
                      null
                    ]
                  },
                  "withholdingRate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "withholdingMinor": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": -99999999999,
                    "maximum": 99999999999
                  },
                  "attachmentFileId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid"
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 500,
                          "pattern": "^[^\\p{Cc}]*$/u"
                        },
                        "categoryCode": {
                          "type": "string",
                          "pattern": "^(?:[a-z_]{2,40}|c:[0-9a-f-]{36})$"
                        },
                        "baseMinor": {
                          "type": "integer",
                          "minimum": -99999999999,
                          "maximum": 99999999999
                        },
                        "taxRate": {
                          "type": "string",
                          "default": "21"
                        },
                        "surchargeRate": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "vatDeductiblePct": {
                          "type": "string"
                        },
                        "irpfDeductiblePct": {
                          "type": "string",
                          "default": "100"
                        },
                        "selfAssessmentRate": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "isInvestment": {
                          "type": "boolean",
                          "default": false
                        },
                        "assetGroup": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 8
                        }
                      },
                      "required": [
                        "categoryCode",
                        "baseMinor",
                        "vatDeductiblePct"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 200
                  }
                },
                "required": [
                  "documentKind",
                  "issueDate",
                  "lines"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Totales",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PurchaseTotals"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/purchases/supplier-defaults": {
      "get": {
        "operationId": "getSupplierDefaults",
        "tags": [
          "purchases"
        ],
        "summary": "Lo último usado con un proveedor (categoría, deducibilidad, tipo de operación)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "required": false,
            "name": "contactId",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 30
            },
            "required": false,
            "name": "taxId",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Sugerencia",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SupplierDefaults"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/purchases": {
      "get": {
        "operationId": "listPurchases",
        "tags": [
          "purchases"
        ],
        "summary": "Documentos de compra, del más reciente al más antiguo, con búsqueda y filtros",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            },
            "required": false,
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 512,
              "pattern": "^[A-Za-z0-9_-]+$"
            },
            "required": false,
            "name": "cursor",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 100
            },
            "required": false,
            "name": "q",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "confirmed"
              ]
            },
            "required": false,
            "name": "status",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            },
            "required": false,
            "name": "from",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            },
            "required": false,
            "name": "to",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "required": false,
            "name": "contactId",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Página",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PurchasePage"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createPurchase",
        "tags": [
          "purchases"
        ],
        "summary": "Registrar una factura recibida, un ticket o un gasto sin factura",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "documentKind": {
                    "type": "string",
                    "enum": [
                      "invoice",
                      "simplified",
                      "other"
                    ]
                  },
                  "operationKind": {
                    "type": "string",
                    "enum": [
                      "domestic",
                      "intra_goods",
                      "intra_services",
                      "import",
                      "reverse_charge_domestic",
                      "not_subject"
                    ],
                    "default": "domestic"
                  },
                  "contactId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid"
                  },
                  "supplierName": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 200,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "supplierTaxId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 30,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "number": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 60,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "issueDate": {
                    "type": "string"
                  },
                  "operationDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "registrationDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "dueDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "paymentMethod": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "transfer",
                      "card",
                      "cash",
                      "direct_debit",
                      "bizum",
                      "other",
                      null
                    ]
                  },
                  "qualifiedSimplified": {
                    "type": "boolean",
                    "default": false
                  },
                  "supplierCashAccounting": {
                    "type": "boolean",
                    "default": false
                  },
                  "withholdingKind": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "professional",
                      "rental",
                      null
                    ]
                  },
                  "withholdingRate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "withholdingMinor": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": -99999999999,
                    "maximum": 99999999999
                  },
                  "attachmentFileId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid"
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 500,
                          "pattern": "^[^\\p{Cc}]*$/u"
                        },
                        "categoryCode": {
                          "type": "string",
                          "pattern": "^(?:[a-z_]{2,40}|c:[0-9a-f-]{36})$"
                        },
                        "baseMinor": {
                          "type": "integer",
                          "minimum": -99999999999,
                          "maximum": 99999999999
                        },
                        "taxRate": {
                          "type": "string",
                          "default": "21"
                        },
                        "surchargeRate": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "vatDeductiblePct": {
                          "type": "string"
                        },
                        "irpfDeductiblePct": {
                          "type": "string",
                          "default": "100"
                        },
                        "selfAssessmentRate": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "isInvestment": {
                          "type": "boolean",
                          "default": false
                        },
                        "assetGroup": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 8
                        }
                      },
                      "required": [
                        "categoryCode",
                        "baseMinor",
                        "vatDeductiblePct"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 200
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "draft",
                      "confirmed"
                    ],
                    "default": "confirmed"
                  }
                },
                "required": [
                  "documentKind",
                  "issueDate",
                  "lines"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ya existía con ese id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Purchase"
                }
              }
            }
          },
          "201": {
            "description": "Registrado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Purchase"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/purchases/{purchaseId}": {
      "get": {
        "operationId": "getPurchase",
        "tags": [
          "purchases"
        ],
        "summary": "Un documento de compra con sus líneas",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "purchaseId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Documento",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Purchase"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "updatePurchase",
        "tags": [
          "purchases"
        ],
        "summary": "Editar un documento de compra (todo a la vez) mientras su periodo no esté cerrado",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "purchaseId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "documentKind": {
                    "type": "string",
                    "enum": [
                      "invoice",
                      "simplified",
                      "other"
                    ]
                  },
                  "operationKind": {
                    "type": "string",
                    "enum": [
                      "domestic",
                      "intra_goods",
                      "intra_services",
                      "import",
                      "reverse_charge_domestic",
                      "not_subject"
                    ],
                    "default": "domestic"
                  },
                  "contactId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid"
                  },
                  "supplierName": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 200,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "supplierTaxId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 30,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "number": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 60,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "issueDate": {
                    "type": "string"
                  },
                  "operationDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "registrationDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "dueDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "paymentMethod": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "transfer",
                      "card",
                      "cash",
                      "direct_debit",
                      "bizum",
                      "other",
                      null
                    ]
                  },
                  "qualifiedSimplified": {
                    "type": "boolean",
                    "default": false
                  },
                  "supplierCashAccounting": {
                    "type": "boolean",
                    "default": false
                  },
                  "withholdingKind": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "professional",
                      "rental",
                      null
                    ]
                  },
                  "withholdingRate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "withholdingMinor": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": -99999999999,
                    "maximum": 99999999999
                  },
                  "attachmentFileId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid"
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 500,
                          "pattern": "^[^\\p{Cc}]*$/u"
                        },
                        "categoryCode": {
                          "type": "string",
                          "pattern": "^(?:[a-z_]{2,40}|c:[0-9a-f-]{36})$"
                        },
                        "baseMinor": {
                          "type": "integer",
                          "minimum": -99999999999,
                          "maximum": 99999999999
                        },
                        "taxRate": {
                          "type": "string",
                          "default": "21"
                        },
                        "surchargeRate": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "vatDeductiblePct": {
                          "type": "string"
                        },
                        "irpfDeductiblePct": {
                          "type": "string",
                          "default": "100"
                        },
                        "selfAssessmentRate": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "isInvestment": {
                          "type": "boolean",
                          "default": false
                        },
                        "assetGroup": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 8
                        }
                      },
                      "required": [
                        "categoryCode",
                        "baseMinor",
                        "vatDeductiblePct"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 200
                  }
                },
                "required": [
                  "version",
                  "documentKind",
                  "issueDate",
                  "lines"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Guardado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Purchase"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deletePurchase",
        "tags": [
          "purchases"
        ],
        "summary": "Borrar un documento de compra sin pagos, si su periodo no está cerrado",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "purchaseId",
            "in": "path"
          }
        ],
        "responses": {
          "204": {
            "description": "Borrado"
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/purchases/{purchaseId}/confirm": {
      "post": {
        "operationId": "confirmPurchase",
        "tags": [
          "purchases"
        ],
        "summary": "Confirmar un borrador (por ejemplo, el que deja la lectura con IA)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "purchaseId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "linkSupplier": {
                    "type": "boolean",
                    "default": false
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Confirmado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Purchase"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/purchases/{purchaseId}/payments": {
      "get": {
        "operationId": "listPurchasePayments",
        "tags": [
          "purchases"
        ],
        "summary": "Pagos de un documento de compra, con lo pendiente",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "purchaseId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Pagos",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PurchasePayments"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createPurchasePayment",
        "tags": [
          "purchases"
        ],
        "summary": "Registrar un pago a proveedor (nunca más de lo pendiente)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "purchaseId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "paidOn": {
                    "type": "string"
                  },
                  "amountMinor": {
                    "type": "integer",
                    "minimum": -99999999999,
                    "maximum": 99999999999
                  },
                  "method": {
                    "type": "string",
                    "enum": [
                      "transfer",
                      "card",
                      "cash",
                      "direct_debit",
                      "bizum",
                      "other"
                    ],
                    "default": "transfer"
                  },
                  "reference": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 140,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  }
                },
                "required": [
                  "paidOn",
                  "amountMinor"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Registrado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PurchasePayments"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/purchases/{purchaseId}/payments/{paymentId}": {
      "delete": {
        "operationId": "deletePurchasePayment",
        "tags": [
          "purchases"
        ],
        "summary": "Borrar un pago a proveedor",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "purchaseId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "paymentId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Borrado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PurchasePayments"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/payment-batches": {
      "get": {
        "operationId": "listPaymentBatches",
        "tags": [
          "payment-batches"
        ],
        "summary": "Remesas de pago a proveedores",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Remesas",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PaymentBatch"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createPaymentBatch",
        "tags": [
          "payment-batches"
        ],
        "summary": "Preparar una remesa con facturas de «Por pagar» (borrador)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "debtorName": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 70,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "debtorIban": {
                    "type": "string",
                    "minLength": 15,
                    "maxLength": 42
                  },
                  "executionDate": {
                    "type": "string"
                  },
                  "purchaseIds": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "minItems": 1,
                    "maxItems": 500
                  }
                },
                "required": [
                  "debtorName",
                  "debtorIban",
                  "executionDate",
                  "purchaseIds"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Creada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentBatch"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/payment-batches/{batchId}": {
      "get": {
        "operationId": "getPaymentBatch",
        "tags": [
          "payment-batches"
        ],
        "summary": "Una remesa",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "batchId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Remesa",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentBatch"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updatePaymentBatch",
        "tags": [
          "payment-batches"
        ],
        "summary": "Cambiar una remesa en borrador",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "batchId",
            "in": "path"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "debtorName": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 70,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "debtorIban": {
                    "type": "string",
                    "minLength": 15,
                    "maxLength": 42
                  },
                  "executionDate": {
                    "type": "string"
                  },
                  "purchaseIds": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "minItems": 1,
                    "maxItems": 500
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cambiada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentBatch"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/payment-batches/{batchId}/cancel": {
      "post": {
        "operationId": "cancelPaymentBatch",
        "tags": [
          "payment-batches"
        ],
        "summary": "Cancelar una remesa no pagada (sus facturas vuelven a «Por pagar»)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "batchId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Cancelada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentBatch"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/inbox": {
      "get": {
        "operationId": "listInbox",
        "tags": [
          "inbox"
        ],
        "summary": "Bandeja de documentos pendientes de convertirse en gasto",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "reading",
                "read",
                "failed",
                "converted",
                "discarded"
              ]
            },
            "required": false,
            "name": "status",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ],
              "default": "false"
            },
            "required": false,
            "name": "all",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Elementos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/InboxItem"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "addToInbox",
        "tags": [
          "inbox"
        ],
        "summary": "Llevar ficheros ya subidos a la bandeja; los repetidos (mismo SHA-256) se avisan y no se duplican",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "fileIds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "minItems": 1,
                    "maxItems": 50
                  },
                  "source": {
                    "type": "string",
                    "enum": [
                      "web",
                      "mobile"
                    ],
                    "default": "web"
                  }
                },
                "required": [
                  "fileIds"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Añadidos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/InboxItem"
                      }
                    },
                    "duplicates": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "fileId": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "existingItemId": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "originalName": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "fileId",
                          "existingItemId",
                          "originalName"
                        ]
                      }
                    }
                  },
                  "required": [
                    "items",
                    "duplicates"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/inbox/{itemId}": {
      "get": {
        "operationId": "getInboxItem",
        "tags": [
          "inbox"
        ],
        "summary": "Un elemento de la bandeja",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "itemId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Elemento",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboxItem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/inbox/{itemId}/discard": {
      "post": {
        "operationId": "discardInboxItem",
        "tags": [
          "inbox"
        ],
        "summary": "Descartar un elemento (el fichero se conserva)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "itemId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Descartado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboxItem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/inbox/{itemId}/content": {
      "get": {
        "operationId": "getInboxContent",
        "tags": [
          "inbox"
        ],
        "summary": "El fichero del elemento, para verlo junto al formulario (lectura auditada)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "itemId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Fichero",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/assets": {
      "get": {
        "operationId": "listAssets",
        "tags": [
          "assets"
        ],
        "summary": "Bienes de inversión con su cuadro de amortización, lo amortizado y lo pendiente",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Bienes",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Asset"
                      }
                    },
                    "year": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "items",
                    "year"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createAsset",
        "tags": [
          "assets"
        ],
        "summary": "Alta manual de un bien (por ejemplo, anterior a Slaupy, con su amortización acumulada)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "table": {
                    "type": "string",
                    "enum": [
                      "simplified",
                      "corporate"
                    ]
                  },
                  "groupCode": {
                    "type": "string",
                    "pattern": "^[SC]\\d{2}$"
                  },
                  "costMinor": {
                    "type": "integer",
                    "minimum": -99999999999,
                    "maximum": 99999999999
                  },
                  "businessUsePct": {
                    "type": "string",
                    "default": "100"
                  },
                  "startDate": {
                    "type": "string"
                  },
                  "coefficientPct": {
                    "type": "string"
                  },
                  "used": {
                    "type": "boolean",
                    "default": false
                  },
                  "freeDepreciation": {
                    "type": "boolean",
                    "default": false
                  },
                  "initialAccumulatedMinor": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": -99999999999,
                    "maximum": 99999999999
                  },
                  "initialUntilYear": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 1990,
                    "maximum": 2100
                  },
                  "purchaseDocumentId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid"
                  }
                },
                "required": [
                  "name",
                  "table",
                  "groupCode",
                  "costMinor",
                  "startDate",
                  "coefficientPct"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Creado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Asset"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/assets/groups": {
      "get": {
        "operationId": "listAssetGroups",
        "tags": [
          "assets"
        ],
        "summary": "Grupos de la tabla de amortización que aplica a la organización",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Tabla",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "table": {
                      "type": "string",
                      "enum": [
                        "simplified",
                        "corporate"
                      ]
                    },
                    "groups": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "code": {
                            "type": "string"
                          },
                          "es": {
                            "type": "string"
                          },
                          "en": {
                            "type": "string"
                          },
                          "maxPct": {
                            "type": "string"
                          },
                          "maxYears": {
                            "type": "integer"
                          }
                        },
                        "required": [
                          "code",
                          "es",
                          "en",
                          "maxPct",
                          "maxYears"
                        ]
                      }
                    }
                  },
                  "required": [
                    "table",
                    "groups"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/assets/{assetId}": {
      "get": {
        "operationId": "getAsset",
        "tags": [
          "assets"
        ],
        "summary": "Un bien con su cuadro completo",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "assetId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Bien",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Asset"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/assets/{assetId}/dispose": {
      "post": {
        "operationId": "disposeAsset",
        "tags": [
          "assets"
        ],
        "summary": "Baja o venta: la amortización se para ese día y se calcula el resultado",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "assetId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "date": {
                    "type": "string"
                  },
                  "priceMinor": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 99999999999
                  }
                },
                "required": [
                  "version",
                  "date",
                  "priceMinor"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Dado de baja",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Asset"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/ai/status": {
      "get": {
        "operationId": "getAiStatus",
        "tags": [
          "ai"
        ],
        "summary": "Lectura con IA: disponibilidad, cupo del mes, uso y aviso",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Estado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AiStatus"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/inbox/{itemId}/read": {
      "post": {
        "operationId": "readInboxItem",
        "tags": [
          "ai"
        ],
        "summary": "Leer (o volver a leer) un elemento de la bandeja con IA; deja un borrador para confirmar",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "itemId",
            "in": "path"
          }
        ],
        "responses": {
          "202": {
            "description": "En cola"
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/inbox/{itemId}/reading": {
      "get": {
        "operationId": "getInboxReading",
        "tags": [
          "ai"
        ],
        "summary": "La última lectura con IA de un elemento: campos dudosos, reintento y borrador",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "itemId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Lectura",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AiReading"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/settings/{year}": {
      "get": {
        "operationId": "getTaxSettings",
        "tags": [
          "tax"
        ],
        "summary": "Perfil fiscal del ejercicio: régimen de IVA, método de IRPF, prorrata, periodicidad…",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 2000,
              "maximum": 2100
            },
            "required": true,
            "name": "year",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Perfil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TaxSettings"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "updateTaxSettings",
        "tags": [
          "tax"
        ],
        "summary": "Guardar el perfil fiscal del ejercicio (con periodos cerrados o presentados, con confirmación)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:file",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 2000,
              "maximum": 2100
            },
            "required": true,
            "name": "year",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "vatRegime": {
                    "type": "string",
                    "enum": [
                      "general",
                      "equivalence_surcharge",
                      "exempt",
                      "small_business"
                    ]
                  },
                  "cashAccounting": {
                    "type": "boolean"
                  },
                  "irpfMethod": {
                    "type": "string",
                    "enum": [
                      "simplified",
                      "normal"
                    ]
                  },
                  "activityKind": {
                    "type": "string",
                    "enum": [
                      "professional",
                      "business"
                    ]
                  },
                  "retentionMajority": {
                    "type": "boolean"
                  },
                  "prorataKind": {
                    "type": "string",
                    "enum": [
                      "none",
                      "general",
                      "special"
                    ]
                  },
                  "prorataProvisionalPct": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "prorataFinalPct": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "filingFrequency": {
                    "type": "string",
                    "enum": [
                      "quarterly",
                      "monthly"
                    ]
                  },
                  "depreciationTable": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "simplified",
                      "corporate",
                      null
                    ]
                  },
                  "activityStartDate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "newActivityReduction": {
                    "type": "boolean"
                  },
                  "directDebit": {
                    "type": "boolean"
                  },
                  "oneStopShop": {
                    "type": [
                      "boolean",
                      "null"
                    ]
                  },
                  "version": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "confirm": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "vatRegime",
                  "cashAccounting",
                  "irpfMethod",
                  "activityKind",
                  "retentionMajority",
                  "prorataKind",
                  "prorataProvisionalPct",
                  "prorataFinalPct",
                  "filingFrequency",
                  "depreciationTable",
                  "activityStartDate",
                  "newActivityReduction",
                  "directDebit",
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Guardado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TaxSettings"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/books/{book}": {
      "get": {
        "operationId": "getTaxBook",
        "tags": [
          "tax"
        ],
        "summary": "Libros registro del ejercicio en el formato común de la AEAT (XLSX) o en CSV legible",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "expedidas",
                "recibidas",
                "bienes",
                "todos"
              ]
            },
            "required": true,
            "name": "book",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 2000,
              "maximum": 2100
            },
            "required": true,
            "name": "year",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "xlsx",
                "csv"
              ],
              "default": "xlsx"
            },
            "required": false,
            "name": "format",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Libro",
            "content": {
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/returns/{model}/{period}": {
      "get": {
        "operationId": "getTaxReturn",
        "tags": [
          "tax"
        ],
        "summary": "Modelo calculado en vivo, con su borrador, sus presentaciones y la traza de cada casilla",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "111",
                "115",
                "130",
                "180",
                "190",
                "303",
                "347",
                "349",
                "390",
                "420",
                "425",
                "ipsi"
              ]
            },
            "required": true,
            "name": "model",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 10
            },
            "required": true,
            "name": "period",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Modelo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TaxReturn"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/returns/{model}/{period}/save-draft": {
      "post": {
        "operationId": "saveTaxReturnDraft",
        "tags": [
          "tax"
        ],
        "summary": "Guardar el borrador: ajustes manuales por casilla (con motivo) y elecciones",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:file",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "111",
                "115",
                "130",
                "180",
                "190",
                "303",
                "347",
                "349",
                "390",
                "420",
                "425",
                "ipsi"
              ]
            },
            "required": true,
            "name": "model",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 10
            },
            "required": true,
            "name": "period",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "adjustments": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "object",
                      "properties": {
                        "value": {
                          "type": "integer"
                        },
                        "reason": {
                          "type": "string",
                          "minLength": 3,
                          "maxLength": 300
                        }
                      },
                      "required": [
                        "value",
                        "reason"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "options": {
                    "type": "object",
                    "properties": {
                      "refund": {
                        "type": "boolean"
                      },
                      "iban": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "maxLength": 34
                      },
                      "offsetLimit": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "minimum": 0
                      },
                      "previousYearNetMinor": {
                        "type": [
                          "integer",
                          "null"
                        ]
                      },
                      "referenceTurnoverMinor": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "minimum": 0
                      },
                      "refundGranted": {
                        "type": "integer",
                        "minimum": 0
                      }
                    },
                    "additionalProperties": false
                  },
                  "version": {
                    "type": "integer",
                    "minimum": 0
                  }
                },
                "required": [
                  "adjustments",
                  "options",
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Borrador",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TaxReturn"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/returns/{model}/{period}/mark-presented": {
      "post": {
        "operationId": "markTaxReturnPresented",
        "tags": [
          "tax"
        ],
        "summary": "Marcar como presentada en la sede de la AEAT, con su justificante: congela las casillas",
        "x-idempotency": "required",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:file",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "111",
                "115",
                "130",
                "180",
                "190",
                "303",
                "347",
                "349",
                "390",
                "420",
                "425",
                "ipsi"
              ]
            },
            "required": true,
            "name": "model",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 10
            },
            "required": true,
            "name": "period",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "receiptCode": {
                    "type": "string",
                    "minLength": 5,
                    "maxLength": 40
                  },
                  "presentedOn": {
                    "type": "string"
                  },
                  "receiptFileId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "receiptCode",
                  "presentedOn"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Presentada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TaxReturn"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/returns/{model}/{period}/rectify": {
      "post": {
        "operationId": "rectifyTaxReturn",
        "tags": [
          "tax"
        ],
        "summary": "Empezar la rectificación de la última presentada: un borrador enlazado a ella",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:file",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "111",
                "115",
                "130",
                "180",
                "190",
                "303",
                "347",
                "349",
                "390",
                "420",
                "425",
                "ipsi"
              ]
            },
            "required": true,
            "name": "model",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 10
            },
            "required": true,
            "name": "period",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Borrador de rectificación",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TaxReturn"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/returns/{model}/{period}/file": {
      "get": {
        "operationId": "getTaxReturnFile",
        "tags": [
          "tax"
        ],
        "summary": "Fichero para importar en el formulario de la sede de la AEAT (ISO-8859-1)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "111",
                "115",
                "130",
                "180",
                "190",
                "303",
                "347",
                "349",
                "390",
                "420",
                "425",
                "ipsi"
              ]
            },
            "required": true,
            "name": "model",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 10
            },
            "required": true,
            "name": "period",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Fichero",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/periods": {
      "get": {
        "operationId": "listTaxPeriods",
        "tags": [
          "tax"
        ],
        "summary": "Periodos del ejercicio, abiertos o cerrados",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 2000,
              "maximum": 2100
            },
            "required": true,
            "name": "year",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Periodos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TaxPeriod"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/periods/{period}/close": {
      "post": {
        "operationId": "closeTaxPeriod",
        "tags": [
          "tax"
        ],
        "summary": "Cerrar un periodo: nada fechado en él se crea, edita ni borra",
        "x-idempotency": "required",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:file",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 10
            },
            "required": true,
            "name": "period",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Cerrado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TaxPeriod"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/periods/{period}/reopen": {
      "post": {
        "operationId": "reopenTaxPeriod",
        "tags": [
          "tax"
        ],
        "summary": "Reabrir un periodo cerrado, con motivo",
        "x-idempotency": "required",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:file",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 10
            },
            "required": true,
            "name": "period",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reason": {
                    "type": "string",
                    "minLength": 10,
                    "maxLength": 500
                  }
                },
                "required": [
                  "reason"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Reabierto",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TaxPeriod"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/dashboard": {
      "get": {
        "operationId": "getDashboard",
        "tags": [
          "tax"
        ],
        "summary": "Panel de inicio: IVA y pago fraccionado estimados del trimestre, plazos, cobros pendientes y el año",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Panel",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Dashboard"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/calendar": {
      "get": {
        "operationId": "getTaxCalendar",
        "tags": [
          "tax"
        ],
        "summary": "Plazos de los modelos que presenta la organización (con días inhábiles) y suscripción",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 2000,
              "maximum": 2100
            },
            "required": false,
            "name": "year",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Calendario",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TaxCalendar"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/calendar/feed": {
      "post": {
        "operationId": "createTaxCalendarFeed",
        "tags": [
          "tax"
        ],
        "summary": "Crea o regenera la dirección de suscripción del calendario fiscal; la anterior deja de funcionar",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:file",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "201": {
            "description": "Dirección nueva: solo se muestra esta vez",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TaxCalendarFeedCreated"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteTaxCalendarFeed",
        "tags": [
          "tax"
        ],
        "summary": "Desactiva la dirección de suscripción del calendario fiscal",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:file",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "204": {
            "description": "Desactivada"
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/annual-income/{year}": {
      "get": {
        "operationId": "getAnnualIncome",
        "tags": [
          "tax"
        ],
        "summary": "Datos de la actividad para la Renta (modelo 100): casillas, trazabilidad y lista de comprobación",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 2000,
              "maximum": 2100
            },
            "required": true,
            "name": "year",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Datos del año",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnnualIncome"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/annual-income/{year}/export": {
      "post": {
        "operationId": "exportAnnualIncome",
        "tags": [
          "tax"
        ],
        "summary": "Paquete para el gestor: resumen en PDF, casillas y libros en CSV y certificados de retenciones",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "export:run",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 2000,
              "maximum": 2100
            },
            "required": true,
            "name": "year",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "ZIP",
            "content": {
              "application/zip": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/annual-income/{year}/certificates": {
      "put": {
        "operationId": "attachWithholdingCertificate",
        "tags": [
          "tax"
        ],
        "summary": "Adjuntar (o sustituir) el certificado de retenciones de un cliente",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:file",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 2000,
              "maximum": 2100
            },
            "required": true,
            "name": "year",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "customerTaxId": {
                    "type": "string",
                    "pattern": "^[A-Z0-9]{2,20}$"
                  },
                  "fileId": {
                    "type": "string",
                    "format": "uuid"
                  }
                },
                "required": [
                  "customerTaxId",
                  "fileId"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Adjuntado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "customerTaxId": {
                      "type": "string"
                    },
                    "fileId": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "id",
                    "customerTaxId",
                    "fileId"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/annual-income/{year}/certificates/{certificateId}": {
      "delete": {
        "operationId": "deleteWithholdingCertificate",
        "tags": [
          "tax"
        ],
        "summary": "Quitar un certificado de retenciones",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:file",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 2000,
              "maximum": 2100
            },
            "required": true,
            "name": "year",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "certificateId",
            "in": "path"
          }
        ],
        "responses": {
          "204": {
            "description": "Quitado"
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/dac7": {
      "get": {
        "operationId": "getDac7Reconciliation",
        "tags": [
          "tax"
        ],
        "summary": "Cuadre DAC7: lo que cada plataforma certifica frente a lo registrado, por trimestre",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 2023,
              "maximum": 2100
            },
            "required": false,
            "name": "year",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Cuadre por canal y trimestre",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Dac7Reconciliation"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/tax/distance-sales": {
      "get": {
        "operationId": "getDistanceSales",
        "tags": [
          "tax"
        ],
        "summary": "Ventas a distancia a consumidores de otros Estados miembros: umbral de 10.000 € y resumen por país",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 2000,
              "maximum": 2100
            },
            "required": true,
            "name": "year",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "csv"
              ],
              "default": "json"
            },
            "required": false,
            "name": "format",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Resumen del ejercicio",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DistanceSales"
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/posting-rules": {
      "get": {
        "operationId": "getPostingRules",
        "tags": [
          "accounting"
        ],
        "summary": "Cuentas a las que van los asientos automáticos: por defecto y las de la organización",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Reglas",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PostingRules"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "updatePostingRules",
        "tags": [
          "accounting"
        ],
        "summary": "Cambiar las cuentas de los asientos automáticos. Afecta a lo que se contabilice desde ahora",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "overrides": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "string",
                      "pattern": "^[1-9][0-9]{0,4}$"
                    }
                  },
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "overrides",
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Guardadas",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PostingRules"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/automatic/pending": {
      "get": {
        "operationId": "listPendingPostings",
        "tags": [
          "accounting"
        ],
        "summary": "Documentos cuyo asiento automático está por hacer o no se ha podido hacer, con el motivo",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "required": false,
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 200,
              "pattern": "^[A-Za-z0-9_-]+$"
            },
            "required": false,
            "name": "cursor",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Pendientes",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PendingPosting"
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "items",
                    "total",
                    "nextCursor"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/automatic/run": {
      "get": {
        "operationId": "getAutomaticPostingRun",
        "tags": [
          "accounting"
        ],
        "summary": "La última tanda de contabilización, con su progreso, y cuántos documentos quedan pendientes",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Tanda",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "run": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/AutomaticPostingRun"
                        },
                        {
                          "type": [
                            "object",
                            "null"
                          ]
                        }
                      ]
                    },
                    "pending": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "run",
                    "pending"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "runAutomaticPosting",
        "tags": [
          "accounting"
        ],
        "summary": "Contabilizar lo pendiente en segundo plano, por lotes. Con `rebuild`, repasa todos los documentos: los que no han cambiado no se tocan. Mientras hay una tanda en marcha devuelve esa",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "rebuild": {
                    "type": "boolean",
                    "default": false
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "En marcha (o ya terminada si no había nada)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "run": {
                      "$ref": "#/components/schemas/AutomaticPostingRun"
                    }
                  },
                  "required": [
                    "run"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/automatic/pending/{pendingId}": {
      "delete": {
        "operationId": "dismissPendingPosting",
        "tags": [
          "accounting"
        ],
        "summary": "Quitar un documento de pendientes porque su asiento se hace a mano",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "pendingId",
            "in": "path"
          }
        ],
        "responses": {
          "204": {
            "description": "Quitado"
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/reports/annual-accounts": {
      "get": {
        "operationId": "getAnnualAccounts",
        "tags": [
          "accounting"
        ],
        "summary": "Balance y cuenta de pérdidas y ganancias (modelo de pymes) del ejercicio, antes de la regularización",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "fiscalYearId",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Cuentas anuales",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnnualAccounts"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/reports/ledger": {
      "get": {
        "operationId": "getLedger",
        "tags": [
          "accounting"
        ],
        "summary": "Libro mayor de una cuenta o de todas las que empiezan por un código, con saldo acumulado",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "fiscalYearId",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "from",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "to",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "pattern": "^[1-9][0-9]{0,11}$"
            },
            "required": true,
            "name": "account",
            "in": "query"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            },
            "required": false,
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 300,
              "pattern": "^[A-Za-z0-9_-]+$"
            },
            "required": false,
            "name": "cursor",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Mayor",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ledger"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/reports/trial-balance": {
      "get": {
        "operationId": "getTrialBalance",
        "tags": [
          "accounting"
        ],
        "summary": "Balance de sumas y saldos al nivel pedido (1 grupo, 3 cuenta, la longitud entera subcuenta)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "fiscalYearId",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "from",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "to",
            "in": "query"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 12
            },
            "required": false,
            "name": "level",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ],
              "default": "false"
            },
            "required": false,
            "name": "beforeClosing",
            "in": "query"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 200
            },
            "required": false,
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 300,
              "pattern": "^[A-Za-z0-9_-]+$"
            },
            "required": false,
            "name": "cursor",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Sumas y saldos",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TrialBalance"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/reports/{report}/export": {
      "get": {
        "operationId": "exportAccountingReport",
        "tags": [
          "accounting"
        ],
        "summary": "Descargar el diario, el mayor o las sumas y saldos en CSV o XLSX",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "journal",
                "ledger",
                "trial-balance"
              ]
            },
            "required": true,
            "name": "report",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "fiscalYearId",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "from",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "to",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "csv",
                "xlsx"
              ],
              "default": "xlsx"
            },
            "required": false,
            "name": "format",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "pattern": "^[1-9][0-9]{0,11}$"
            },
            "required": false,
            "name": "account",
            "in": "query"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 12
            },
            "required": false,
            "name": "level",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ],
              "default": "false"
            },
            "required": false,
            "name": "beforeClosing",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Fichero",
            "content": {
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/export-settings": {
      "get": {
        "operationId": "getAccountingExportSettings",
        "tags": [
          "accounting"
        ],
        "summary": "Programa, código de empresa y dígitos de la última exportación para la gestoría",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Ajustes",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountingExportSettings"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/exports/{program}": {
      "get": {
        "operationId": "exportAccountingForAdvisor",
        "tags": [
          "accounting"
        ],
        "summary": "Descargar el diario de un periodo para el programa de la gestoría (a3, Contasol o Sage 50 / ContaPlus)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "a3",
                "contasol",
                "sage"
              ]
            },
            "required": true,
            "name": "program",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "fiscalYearId",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "from",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "to",
            "in": "query"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 99999
            },
            "required": false,
            "name": "companyCode",
            "in": "query"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 6,
              "maximum": 12
            },
            "required": false,
            "name": "accountLength",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Fichero de importación",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/zip": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/payrolls": {
      "get": {
        "operationId": "listPayrolls",
        "tags": [
          "accounting"
        ],
        "summary": "Nóminas resumidas de un año",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 2000,
              "maximum": 2100
            },
            "required": true,
            "name": "year",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Nóminas",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PayrollSummary"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createPayroll",
        "tags": [
          "accounting"
        ],
        "summary": "Registrar las nóminas de un mes: entran en el 111, el 190 y el asiento de sueldos",
        "x-idempotency": "required",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "period": {
                    "type": "string",
                    "pattern": "^\\d{4}-(0[1-9]|1[0-2])$"
                  },
                  "paidOn": {
                    "type": "string"
                  },
                  "label": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 120
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "employeeName": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 120
                        },
                        "employeeTaxId": {
                          "type": "string",
                          "minLength": 8,
                          "maxLength": 12
                        },
                        "postalCode": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "pattern": "^\\d{5}$"
                        },
                        "grossMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000,
                          "default": 0
                        },
                        "withheldMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000,
                          "default": 0
                        },
                        "inKindMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000,
                          "default": 0
                        },
                        "inKindWithheldMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000,
                          "default": 0
                        },
                        "employeeSsMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000,
                          "default": 0
                        },
                        "employerSsMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000,
                          "default": 0
                        }
                      },
                      "required": [
                        "employeeName",
                        "employeeTaxId"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 1000
                  }
                },
                "required": [
                  "period",
                  "paidOn",
                  "lines"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Registrada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PayrollSummary"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/payrolls/{payrollId}": {
      "get": {
        "operationId": "getPayroll",
        "tags": [
          "accounting"
        ],
        "summary": "Una nómina resumida con sus empleados",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "payrollId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Nómina",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PayrollSummary"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "updatePayroll",
        "tags": [
          "accounting"
        ],
        "summary": "Corregir una nómina resumida mientras su trimestre esté abierto",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "payrollId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "period": {
                    "type": "string",
                    "pattern": "^\\d{4}-(0[1-9]|1[0-2])$"
                  },
                  "paidOn": {
                    "type": "string"
                  },
                  "label": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 120
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "employeeName": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 120
                        },
                        "employeeTaxId": {
                          "type": "string",
                          "minLength": 8,
                          "maxLength": 12
                        },
                        "postalCode": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "pattern": "^\\d{5}$"
                        },
                        "grossMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000,
                          "default": 0
                        },
                        "withheldMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000,
                          "default": 0
                        },
                        "inKindMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000,
                          "default": 0
                        },
                        "inKindWithheldMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000,
                          "default": 0
                        },
                        "employeeSsMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000,
                          "default": 0
                        },
                        "employerSsMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000,
                          "default": 0
                        }
                      },
                      "required": [
                        "employeeName",
                        "employeeTaxId"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 1000
                  },
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "period",
                  "paidOn",
                  "lines",
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Guardada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PayrollSummary"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deletePayroll",
        "tags": [
          "accounting"
        ],
        "summary": "Borrar una nómina resumida mientras su trimestre esté abierto",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "payrollId",
            "in": "path"
          }
        ],
        "responses": {
          "204": {
            "description": "Borrada"
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/approvals/policy": {
      "get": {
        "operationId": "getApprovalPolicy",
        "tags": [
          "approvals"
        ],
        "summary": "Importe a partir del cual una factura de proveedor necesita aprobación para pagarse",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Política",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApprovalPolicy"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/approvals": {
      "get": {
        "operationId": "listApprovals",
        "tags": [
          "approvals"
        ],
        "summary": "Facturas de proveedor con aprobación, las pendientes primero",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "purchases:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "approved",
                "rejected"
              ]
            },
            "required": false,
            "name": "status",
            "in": "query"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 100
            },
            "required": false,
            "name": "limit",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Aprobaciones",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Approval"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/corporate-tax/200": {
      "get": {
        "operationId": "getModel200Draft",
        "tags": [
          "accounting"
        ],
        "summary": "Borrador guiado del modelo 200: resultado contable, ajustes, bases negativas, tipo y cuota",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "fiscalYearId",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "micro",
                "small",
                "general"
              ],
              "default": "micro"
            },
            "required": false,
            "name": "size",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ],
              "default": "false"
            },
            "required": false,
            "name": "newEntity",
            "in": "query"
          },
          {
            "schema": {
              "type": [
                "integer",
                "null"
              ],
              "minimum": -100000000000,
              "maximum": 100000000000,
              "default": 0
            },
            "required": false,
            "name": "adjustmentsMinor",
            "in": "query"
          },
          {
            "schema": {
              "type": [
                "integer",
                "null"
              ],
              "minimum": 0,
              "maximum": 100000000000,
              "default": 0
            },
            "required": false,
            "name": "pendingLossesMinor",
            "in": "query"
          },
          {
            "schema": {
              "type": [
                "integer",
                "null"
              ],
              "minimum": 0,
              "maximum": 100000000000,
              "default": 0
            },
            "required": false,
            "name": "deductionsMinor",
            "in": "query"
          },
          {
            "schema": {
              "type": [
                "integer",
                "null"
              ],
              "minimum": 0,
              "maximum": 100000000000,
              "default": 0
            },
            "required": false,
            "name": "paymentsOnAccountMinor",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Borrador",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Model200Draft"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/corporate-tax/202": {
      "get": {
        "operationId": "getModel202",
        "tags": [
          "accounting"
        ],
        "summary": "Pago fraccionado (modelo 202) del periodo, por la cuota del último 200 o por la base de los meses transcurridos",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "fiscalYearId",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "1P",
                "2P",
                "3P"
              ]
            },
            "required": true,
            "name": "period",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "quota",
                "base"
              ]
            },
            "required": true,
            "name": "modality",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "micro",
                "small",
                "general"
              ],
              "default": "micro"
            },
            "required": false,
            "name": "size",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ],
              "default": "false"
            },
            "required": false,
            "name": "newEntity",
            "in": "query"
          },
          {
            "schema": {
              "type": [
                "integer",
                "null"
              ],
              "minimum": 0,
              "maximum": 100000000000,
              "default": 0
            },
            "required": false,
            "name": "lastQuotaMinor",
            "in": "query"
          },
          {
            "schema": {
              "type": [
                "integer",
                "null"
              ],
              "minimum": 0,
              "maximum": 100000000000,
              "default": 0
            },
            "required": false,
            "name": "previousPaymentsMinor",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Pago fraccionado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Model202"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/chart": {
      "get": {
        "operationId": "getAccountChart",
        "tags": [
          "accounting"
        ],
        "summary": "Plan de cuentas de la organización (o null si aún no se ha creado)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Plan",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "chart": {
                      "$ref": "#/components/schemas/AccountChart"
                    }
                  },
                  "required": [
                    "chart"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createAccountChart",
        "tags": [
          "accounting"
        ],
        "summary": "Crear el plan de cuentas desde el PGC de pymes, con las subcuentas de los contactos",
        "x-idempotency": "required",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "subaccountLength": {
                    "type": "integer",
                    "minimum": 6,
                    "maximum": 12,
                    "default": 8
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Creado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountChart"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/accounts": {
      "get": {
        "operationId": "listAccounts",
        "tags": [
          "accounting"
        ],
        "summary": "Cuentas y subcuentas por código, con búsqueda por código o nombre",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 60
            },
            "required": false,
            "name": "q",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "required": false,
            "name": "postable",
            "in": "query"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000,
              "default": 200
            },
            "required": false,
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 200,
              "pattern": "^[A-Za-z0-9_-]+$"
            },
            "required": false,
            "name": "cursor",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Cuentas",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Account"
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "items",
                    "nextCursor"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createAccount",
        "tags": [
          "accounting"
        ],
        "summary": "Crear una subcuenta bajo una cuenta del plan, o la de un contacto (430x, 400x, 410x)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "anyOf": [
                  {
                    "type": "object",
                    "properties": {
                      "code": {
                        "type": "string",
                        "pattern": "^[1-9][0-9]{5,11}$"
                      },
                      "name": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 200
                      }
                    },
                    "required": [
                      "code",
                      "name"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "contactId": {
                        "type": "string"
                      },
                      "role": {
                        "type": "string",
                        "enum": [
                          "customer",
                          "supplier",
                          "creditor"
                        ]
                      }
                    },
                    "required": [
                      "contactId",
                      "role"
                    ],
                    "additionalProperties": false
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Creada (o la que ya tenía el contacto)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/fiscal-years": {
      "get": {
        "operationId": "listFiscalYears",
        "tags": [
          "accounting"
        ],
        "summary": "Ejercicios contables, del más antiguo al más reciente",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Ejercicios",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/FiscalYear"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createFiscalYear",
        "tags": [
          "accounting"
        ],
        "summary": "Abrir un ejercicio (hasta doce meses, seguido del anterior o del siguiente)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "startDate": {
                    "type": "string"
                  },
                  "endDate": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 40
                  }
                },
                "required": [
                  "startDate",
                  "endDate"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Creado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FiscalYear"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/fiscal-years/{yearId}/closing": {
      "get": {
        "operationId": "getFiscalYearClosing",
        "tags": [
          "accounting"
        ],
        "summary": "Vista previa del cierre: resultado, asientos que se harán y lo que lo impide",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "yearId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Vista previa",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FiscalYearClosing"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/year-end-run": {
      "get": {
        "operationId": "getFiscalYearRun",
        "tags": [
          "accounting"
        ],
        "summary": "El último cierre o reapertura de ejercicio, con su progreso y su resultado",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Tanda",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "run": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/FiscalYearRun"
                        },
                        {
                          "type": [
                            "object",
                            "null"
                          ]
                        }
                      ]
                    }
                  },
                  "required": [
                    "run"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/entries": {
      "get": {
        "operationId": "listJournalEntries",
        "tags": [
          "accounting"
        ],
        "summary": "Libro diario de un ejercicio: contabilizados por número (o borradores)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "fiscalYearId",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "posted",
                "draft"
              ],
              "default": "posted"
            },
            "required": false,
            "name": "status",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "desc"
            },
            "required": false,
            "name": "order",
            "in": "query"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "required": false,
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 200,
              "pattern": "^[A-Za-z0-9_-]+$"
            },
            "required": false,
            "name": "cursor",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Asientos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/JournalEntry"
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "items",
                    "nextCursor"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createJournalEntry",
        "tags": [
          "accounting"
        ],
        "summary": "Alta manual de un asiento, como borrador o contabilizado (contabilizado exige `id`)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "date": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 300
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "accountId": {
                          "type": "string"
                        },
                        "debitMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000
                        },
                        "creditMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 300
                        }
                      },
                      "required": [
                        "accountId",
                        "debitMinor",
                        "creditMinor"
                      ],
                      "additionalProperties": false
                    },
                    "maxItems": 500
                  },
                  "id": {
                    "type": "string"
                  },
                  "post": {
                    "type": "boolean",
                    "default": false
                  }
                },
                "required": [
                  "date",
                  "description",
                  "lines"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Creado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JournalEntry"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/entries/{entryId}": {
      "get": {
        "operationId": "getJournalEntry",
        "tags": [
          "accounting"
        ],
        "summary": "Un asiento con sus líneas",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "entryId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Asiento",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JournalEntry"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "updateJournalEntry",
        "tags": [
          "accounting"
        ],
        "summary": "Cambiar un borrador (fecha, concepto y líneas)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "entryId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "date": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 300
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "accountId": {
                          "type": "string"
                        },
                        "debitMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000
                        },
                        "creditMinor": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 100000000000
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 300
                        }
                      },
                      "required": [
                        "accountId",
                        "debitMinor",
                        "creditMinor"
                      ],
                      "additionalProperties": false
                    },
                    "maxItems": 500
                  },
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "date",
                  "description",
                  "lines",
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cambiado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JournalEntry"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteJournalEntry",
        "tags": [
          "accounting"
        ],
        "summary": "Borrar un borrador (los contabilizados se anulan con un contraasiento)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "entryId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "required": true,
            "name": "version",
            "in": "query"
          }
        ],
        "responses": {
          "204": {
            "description": "Borrado"
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/entries/{entryId}/post": {
      "post": {
        "operationId": "postJournalEntry",
        "tags": [
          "accounting"
        ],
        "summary": "Contabilizar un borrador: recibe número y ya no cambia",
        "x-idempotency": "required",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "entryId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Contabilizado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JournalEntry"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/entries/{entryId}/reverse": {
      "post": {
        "operationId": "reverseJournalEntry",
        "tags": [
          "accounting"
        ],
        "summary": "Anular un asiento contabilizado con su contraasiento",
        "x-idempotency": "required",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "entryId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "date": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 300
                  }
                },
                "required": [
                  "date"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Contraasiento",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JournalEntry"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/documents/{sourceType}/{sourceId}/entries": {
      "get": {
        "operationId": "listDocumentEntries",
        "tags": [
          "accounting"
        ],
        "summary": "Asientos de un documento (factura, compra, cobro, pago, bien, modelo o nómina), con sus anulaciones",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "accounting:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "invoice",
                "purchase_document",
                "invoice_payment",
                "purchase_payment",
                "asset_depreciation",
                "payroll",
                "tax_return"
              ]
            },
            "required": true,
            "name": "sourceType",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "sourceId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Asientos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/JournalEntry"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/accounting/originals": {
      "get": {
        "operationId": "exportOriginals",
        "tags": [
          "accounting"
        ],
        "summary": "Descargar en un ZIP los PDF de las facturas emitidas y los adjuntos de las compras de un periodo",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "files:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "from",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "to",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "ZIP",
            "content": {
              "application/zip": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/company": {
      "get": {
        "operationId": "getCompany",
        "tags": [
          "orgs"
        ],
        "summary": "Datos de la sociedad: registro mercantil, administradores y socios",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "org:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Sociedad",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Company"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/imports": {
      "get": {
        "operationId": "listImports",
        "tags": [
          "import"
        ],
        "summary": "Últimas importaciones",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Importaciones",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ImportBatch"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createImport",
        "tags": [
          "import"
        ],
        "summary": "Leer una hoja de cálculo subida y proponer la asignación de columnas",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "fileId": {
                    "type": "string"
                  },
                  "entity": {
                    "type": "string",
                    "enum": [
                      "contacts",
                      "products",
                      "invoices",
                      "purchases"
                    ]
                  },
                  "source": {
                    "type": "string",
                    "enum": [
                      "auto",
                      "other",
                      "aeat",
                      "holded",
                      "quipu",
                      "contasimple",
                      "billin",
                      "anfix",
                      "facturadirecta",
                      "sage50",
                      "sage200",
                      "sageactive",
                      "a3",
                      "declarando",
                      "cuentica",
                      "factorial",
                      "zoho",
                      "gestoria"
                    ]
                  }
                },
                "required": [
                  "fileId",
                  "entity"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Leída",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "batch": {
                      "$ref": "#/components/schemas/ImportBatch"
                    },
                    "analysis": {
                      "$ref": "#/components/schemas/ImportAnalysis"
                    }
                  },
                  "required": [
                    "batch",
                    "analysis"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/imports/{importId}": {
      "get": {
        "operationId": "getImport",
        "tags": [
          "import"
        ],
        "summary": "Estado de una importación",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "importId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Importación",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImportBatch"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/imports/{importId}/columns": {
      "post": {
        "operationId": "analyzeImport",
        "tags": [
          "import"
        ],
        "summary": "Columnas de otra hoja u otra fila de cabecera, con su asignación propuesta",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "importId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "sheet": {
                    "type": "string",
                    "maxLength": 100
                  },
                  "headerRow": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 50
                  },
                  "source": {
                    "type": "string",
                    "enum": [
                      "auto",
                      "other",
                      "aeat",
                      "holded",
                      "quipu",
                      "contasimple",
                      "billin",
                      "anfix",
                      "facturadirecta",
                      "sage50",
                      "sage200",
                      "sageactive",
                      "a3",
                      "declarando",
                      "cuentica",
                      "factorial",
                      "zoho",
                      "gestoria"
                    ]
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Columnas",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImportAnalysis"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/imports/{importId}/preview": {
      "post": {
        "operationId": "previewImport",
        "tags": [
          "import"
        ],
        "summary": "Validar todas las filas con una asignación de columnas, sin escribir nada",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "importId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "mapping": {
                    "type": "object",
                    "additionalProperties": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "minimum": 0,
                      "maximum": 999
                    }
                  },
                  "options": {
                    "type": "object",
                    "properties": {
                      "sheet": {
                        "type": "string",
                        "maxLength": 100
                      },
                      "headerRow": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 50,
                        "default": 1
                      },
                      "dateOrder": {
                        "type": "string",
                        "enum": [
                          "dmy",
                          "mdy",
                          "ymd"
                        ],
                        "default": "dmy"
                      },
                      "decimal": {
                        "type": "string",
                        "enum": [
                          "auto",
                          "comma",
                          "dot"
                        ],
                        "default": "auto"
                      },
                      "nextNumbers": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "seriesId": {
                              "type": "string"
                            },
                            "year": {
                              "type": "integer",
                              "minimum": 2000,
                              "maximum": 2100
                            },
                            "next": {
                              "type": "integer",
                              "minimum": 1,
                              "maximum": 999999999
                            }
                          },
                          "required": [
                            "seriesId",
                            "year",
                            "next"
                          ],
                          "additionalProperties": false
                        },
                        "maxItems": 20
                      },
                      "source": {
                        "type": "string",
                        "enum": [
                          "auto",
                          "other",
                          "aeat",
                          "holded",
                          "quipu",
                          "contasimple",
                          "billin",
                          "anfix",
                          "facturadirecta",
                          "sage50",
                          "sage200",
                          "sageactive",
                          "a3",
                          "declarando",
                          "cuentica",
                          "factorial",
                          "zoho",
                          "gestoria"
                        ]
                      },
                      "profile": {
                        "type": "string",
                        "maxLength": 60,
                        "pattern": "^[a-z0-9-]+$"
                      }
                    },
                    "default": {
                      "headerRow": 1,
                      "dateOrder": "dmy",
                      "decimal": "auto"
                    },
                    "additionalProperties": false
                  }
                },
                "required": [
                  "mapping"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Vista previa",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImportPreview"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/imports/{importId}/run": {
      "post": {
        "operationId": "runImport",
        "tags": [
          "import"
        ],
        "summary": "Importar las filas válidas (en la petición si son pocas; si no, en segundo plano)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "importId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "mapping": {
                    "type": "object",
                    "additionalProperties": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "minimum": 0,
                      "maximum": 999
                    }
                  },
                  "options": {
                    "type": "object",
                    "properties": {
                      "sheet": {
                        "type": "string",
                        "maxLength": 100
                      },
                      "headerRow": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 50,
                        "default": 1
                      },
                      "dateOrder": {
                        "type": "string",
                        "enum": [
                          "dmy",
                          "mdy",
                          "ymd"
                        ],
                        "default": "dmy"
                      },
                      "decimal": {
                        "type": "string",
                        "enum": [
                          "auto",
                          "comma",
                          "dot"
                        ],
                        "default": "auto"
                      },
                      "nextNumbers": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "seriesId": {
                              "type": "string"
                            },
                            "year": {
                              "type": "integer",
                              "minimum": 2000,
                              "maximum": 2100
                            },
                            "next": {
                              "type": "integer",
                              "minimum": 1,
                              "maximum": 999999999
                            }
                          },
                          "required": [
                            "seriesId",
                            "year",
                            "next"
                          ],
                          "additionalProperties": false
                        },
                        "maxItems": 20
                      },
                      "source": {
                        "type": "string",
                        "enum": [
                          "auto",
                          "other",
                          "aeat",
                          "holded",
                          "quipu",
                          "contasimple",
                          "billin",
                          "anfix",
                          "facturadirecta",
                          "sage50",
                          "sage200",
                          "sageactive",
                          "a3",
                          "declarando",
                          "cuentica",
                          "factorial",
                          "zoho",
                          "gestoria"
                        ]
                      },
                      "profile": {
                        "type": "string",
                        "maxLength": 60,
                        "pattern": "^[a-z0-9-]+$"
                      }
                    },
                    "default": {
                      "headerRow": 1,
                      "dateOrder": "dmy",
                      "decimal": "auto"
                    },
                    "additionalProperties": false
                  }
                },
                "required": [
                  "mapping"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Importación hecha o en cola",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImportBatch"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/imports/{importId}/undo": {
      "post": {
        "operationId": "undoImport",
        "tags": [
          "import"
        ],
        "summary": "Deshacer una importación completa: la organización queda como estaba",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "importId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Deshecha",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImportBatch"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/imports/{importId}/rejected": {
      "get": {
        "operationId": "downloadImportRejected",
        "tags": [
          "import"
        ],
        "summary": "CSV con las filas rechazadas y el motivo, para corregirlas y volver a importarlas",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:write",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "importId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "CSV (UTF-8, separado por punto y coma)",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/sales-channels": {
      "get": {
        "operationId": "listSalesChannels",
        "tags": [
          "sales-channels"
        ],
        "summary": "Canales de venta de la organización (tienda, marketplace, pasarela de pago)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "channels:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Canales, las plataformas cuyo informe se sabe leer y cuántos activos admite el plan",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SalesChannel"
                      }
                    },
                    "kinds": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "enum": [
                          "shopify",
                          "amazon",
                          "stripe",
                          "other"
                        ]
                      }
                    },
                    "limit": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "items",
                    "kinds",
                    "limit"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/reconciliation/inbox": {
      "get": {
        "operationId": "listReconciliationInbox",
        "tags": [
          "bank"
        ],
        "summary": "Movimientos por conciliar con sus candidatos, de más reciente a más antiguo",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "accountId",
            "in": "query"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 25
            },
            "required": false,
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 200,
              "pattern": "^[A-Za-z0-9_-]+$"
            },
            "required": false,
            "name": "cursor",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Bandeja",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ReconciliationInboxItem"
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "items",
                    "nextCursor"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/transactions/{transactionId}/reconciliation": {
      "get": {
        "operationId": "getReconciliation",
        "tags": [
          "bank"
        ],
        "summary": "Lo conciliado de un movimiento y sus candidatos",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "transactionId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Conciliación",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "transaction": {
                      "$ref": "#/components/schemas/BankTransaction"
                    },
                    "parts": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ReconciliationPart"
                      }
                    },
                    "candidates": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/MatchCandidate"
                      }
                    }
                  },
                  "required": [
                    "transaction",
                    "parts",
                    "candidates"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/transactions/{transactionId}/reconcile": {
      "post": {
        "operationId": "reconcileTransaction",
        "tags": [
          "bank"
        ],
        "summary": "Confirmar a qué corresponde un movimiento (una o varias facturas, compras o un traspaso): crea los cobros y pagos",
        "x-idempotency": "required",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "transactionId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "parts": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "target": {
                          "type": "string",
                          "enum": [
                            "invoice",
                            "purchase",
                            "own_transfer"
                          ]
                        },
                        "targetId": {
                          "type": "string"
                        },
                        "amountMinor": {
                          "type": "integer",
                          "minimum": -100000000000,
                          "maximum": 100000000000
                        }
                      },
                      "required": [
                        "target",
                        "targetId",
                        "amountMinor"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 20
                  },
                  "origin": {
                    "type": "string",
                    "enum": [
                      "suggestion",
                      "manual",
                      "ai"
                    ],
                    "default": "manual"
                  }
                },
                "required": [
                  "parts"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Conciliado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "transaction": {
                      "$ref": "#/components/schemas/BankTransaction"
                    },
                    "parts": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ReconciliationPart"
                      }
                    }
                  },
                  "required": [
                    "transaction",
                    "parts"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/transactions/{transactionId}/undo-reconciliation": {
      "post": {
        "operationId": "undoTransactionReconciliation",
        "tags": [
          "bank"
        ],
        "summary": "Deshacer la conciliación: borra los cobros y pagos que creó",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "transactionId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Deshecho",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BankTransaction"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/transactions/{transactionId}/ignore": {
      "post": {
        "operationId": "ignoreTransaction",
        "tags": [
          "bank"
        ],
        "summary": "Apartar un movimiento que no hay que conciliar, o devolverlo a la bandeja",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "transactionId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "ignored": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "ignored"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Hecho",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BankTransaction"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/reconciliation/ai-suggestions": {
      "post": {
        "operationId": "requestAiMatches",
        "tags": [
          "bank"
        ],
        "summary": "Pedir a la IA propuestas para los movimientos dudosos. Solo propone; nunca concilia",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "transactionIds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "maxItems": 20
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "En cola"
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/transactions/{transactionId}/ai-suggestion": {
      "delete": {
        "operationId": "discardAiMatch",
        "tags": [
          "bank"
        ],
        "summary": "Descartar la propuesta de la IA para un movimiento",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "transactionId",
            "in": "path"
          }
        ],
        "responses": {
          "204": {
            "description": "Descartada"
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/transactions/{transactionId}/rule-proposal/confirm": {
      "post": {
        "operationId": "confirmRuleProposal",
        "tags": [
          "bank"
        ],
        "summary": "Confirmar la regla propuesta para un movimiento: lo aparta o crea el gasto y lo concilia (si el gasto pasa del importe de aprobación, espera a que se apruebe)",
        "x-idempotency": "required",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "transactionId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "transaction": {
                      "$ref": "#/components/schemas/BankTransaction"
                    },
                    "outcome": {
                      "type": "string",
                      "enum": [
                        "ignored",
                        "expense",
                        "awaiting_approval"
                      ]
                    }
                  },
                  "required": [
                    "transaction",
                    "outcome"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/transactions/{transactionId}/rule-proposal": {
      "delete": {
        "operationId": "discardRuleProposal",
        "tags": [
          "bank"
        ],
        "summary": "Descartar la regla propuesta para un movimiento; sigue en la bandeja",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "transactionId",
            "in": "path"
          }
        ],
        "responses": {
          "204": {
            "description": "Descartada"
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/rules": {
      "get": {
        "operationId": "listBankRules",
        "tags": [
          "bank"
        ],
        "summary": "Reglas de movimientos de la organización, por prioridad",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Reglas",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/BankRule"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createBankRule",
        "tags": [
          "bank"
        ],
        "summary": "Crear una regla: «los movimientos con este texto son este gasto» o «apártalos»",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "enabled": {
                    "type": "boolean",
                    "default": true
                  },
                  "autoConfirm": {
                    "type": "boolean",
                    "default": false
                  },
                  "priority": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 1000,
                    "default": 100
                  },
                  "direction": {
                    "type": "string",
                    "enum": [
                      "in",
                      "out",
                      "any"
                    ],
                    "default": "out"
                  },
                  "textContains": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 80
                  },
                  "bankAccountId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "amountMinMinor": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0,
                    "maximum": 100000000000
                  },
                  "amountMaxMinor": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0,
                    "maximum": 100000000000
                  },
                  "action": {
                    "type": "string",
                    "enum": [
                      "expense",
                      "ignore"
                    ]
                  },
                  "categoryCode": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 60
                  },
                  "supplierName": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 200
                  },
                  "contactId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "name",
                  "textContains",
                  "action"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Creada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BankRule"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/rules/{ruleId}": {
      "put": {
        "operationId": "updateBankRule",
        "tags": [
          "bank"
        ],
        "summary": "Cambiar una regla. No toca lo que ya aplicó",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "ruleId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "enabled": {
                    "type": "boolean",
                    "default": true
                  },
                  "autoConfirm": {
                    "type": "boolean",
                    "default": false
                  },
                  "priority": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 1000,
                    "default": 100
                  },
                  "direction": {
                    "type": "string",
                    "enum": [
                      "in",
                      "out",
                      "any"
                    ],
                    "default": "out"
                  },
                  "textContains": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 80
                  },
                  "bankAccountId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "amountMinMinor": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0,
                    "maximum": 100000000000
                  },
                  "amountMaxMinor": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0,
                    "maximum": 100000000000
                  },
                  "action": {
                    "type": "string",
                    "enum": [
                      "expense",
                      "ignore"
                    ]
                  },
                  "categoryCode": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 60
                  },
                  "supplierName": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 200
                  },
                  "contactId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "name",
                  "textContains",
                  "action",
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Guardada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BankRule"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteBankRule",
        "tags": [
          "bank"
        ],
        "summary": "Borrar una regla. Lo que ya aplicó se queda",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "ruleId",
            "in": "path"
          }
        ],
        "responses": {
          "204": {
            "description": "Borrada"
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/rules/apply": {
      "post": {
        "operationId": "applyBankRules",
        "tags": [
          "bank"
        ],
        "summary": "Aplicar las reglas a los movimientos por conciliar",
        "x-idempotency": "required",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Aplicadas",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "applied": {
                      "type": "integer"
                    },
                    "ignored": {
                      "type": "integer"
                    },
                    "expenses": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "applied",
                    "ignored",
                    "expenses"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/accounts": {
      "get": {
        "operationId": "listBankAccounts",
        "tags": [
          "bank"
        ],
        "summary": "Cuentas bancarias de la organización",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "required": false,
            "name": "archived",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Cuentas",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/BankAccount"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createBankAccount",
        "tags": [
          "bank"
        ],
        "summary": "Dar de alta una cuenta para alimentarla con extractos",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "iban": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 42
                  },
                  "currency": {
                    "type": "string",
                    "enum": [
                      "EUR"
                    ],
                    "default": "EUR"
                  }
                },
                "required": [
                  "name"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Creada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BankAccount"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/accounts/{accountId}": {
      "get": {
        "operationId": "getBankAccount",
        "tags": [
          "bank"
        ],
        "summary": "Una cuenta bancaria",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "accountId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Cuenta",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BankAccount"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateBankAccount",
        "tags": [
          "bank"
        ],
        "summary": "Cambiar el nombre o el IBAN de una cuenta, o archivarla",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "accountId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "iban": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 42
                  },
                  "archived": {
                    "type": "boolean"
                  },
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cuenta",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BankAccount"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/transactions": {
      "get": {
        "operationId": "listBankTransactions",
        "tags": [
          "bank"
        ],
        "summary": "Movimientos, del más reciente al más antiguo, con filtros y totales",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "required": false,
            "name": "accountId",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "format": "date"
            },
            "required": false,
            "name": "from",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "format": "date"
            },
            "required": false,
            "name": "to",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 100
            },
            "required": false,
            "name": "q",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "in",
                "out"
              ]
            },
            "required": false,
            "name": "direction",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "matched",
                "ignored"
              ]
            },
            "required": false,
            "name": "status",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "required": false,
            "name": "statementId",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "required": false,
            "name": "cursor",
            "in": "query"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "required": false,
            "name": "limit",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Movimientos",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BankTransactionPage"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/transactions/{transactionId}": {
      "get": {
        "operationId": "getBankTransaction",
        "tags": [
          "bank"
        ],
        "summary": "Un movimiento",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "transactionId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Movimiento",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BankTransaction"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/statements": {
      "get": {
        "operationId": "listBankStatements",
        "tags": [
          "bank"
        ],
        "summary": "Últimos extractos subidos",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Extractos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/BankStatement"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createBankStatement",
        "tags": [
          "bank"
        ],
        "summary": "Leer un extracto subido (Norma 43, CSV o Excel) y comprobarlo, sin escribir movimientos",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "fileId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "mapping": {
                    "type": "object",
                    "properties": {
                      "headerRow": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 60
                      },
                      "date": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 99
                      },
                      "valueDate": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "minimum": 0,
                        "maximum": 99
                      },
                      "description": {
                        "type": "array",
                        "items": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 99
                        },
                        "minItems": 1,
                        "maxItems": 4
                      },
                      "amount": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "minimum": 0,
                        "maximum": 99
                      },
                      "debit": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "minimum": 0,
                        "maximum": 99
                      },
                      "credit": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "minimum": 0,
                        "maximum": 99
                      },
                      "balance": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "minimum": 0,
                        "maximum": 99
                      },
                      "counterparty": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "minimum": 0,
                        "maximum": 99
                      },
                      "reference": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "minimum": 0,
                        "maximum": 99
                      },
                      "dateOrder": {
                        "type": "string",
                        "enum": [
                          "dmy",
                          "mdy",
                          "ymd"
                        ],
                        "default": "dmy"
                      }
                    },
                    "required": [
                      "headerRow",
                      "date",
                      "description"
                    ],
                    "additionalProperties": false
                  },
                  "sheet": {
                    "type": "string",
                    "maxLength": 100
                  }
                },
                "required": [
                  "fileId"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Leído",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BankStatementPreview"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/statements/{statementId}": {
      "get": {
        "operationId": "getBankStatement",
        "tags": [
          "bank"
        ],
        "summary": "Estado de un extracto",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "statementId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Extracto",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BankStatement"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/statements/{statementId}/run": {
      "post": {
        "operationId": "runBankStatement",
        "tags": [
          "bank"
        ],
        "summary": "Importar los movimientos en las cuentas elegidas (sin duplicar los que ya están)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "statementId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "accounts": {
                    "type": "array",
                    "items": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "key": {
                              "type": "string",
                              "maxLength": 40
                            },
                            "accountId": {
                              "type": "string",
                              "format": "uuid"
                            }
                          },
                          "required": [
                            "key",
                            "accountId"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "key": {
                              "type": "string",
                              "maxLength": 40
                            },
                            "create": {
                              "type": "object",
                              "properties": {
                                "name": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 80
                                }
                              },
                              "required": [
                                "name"
                              ],
                              "additionalProperties": false
                            }
                          },
                          "required": [
                            "key",
                            "create"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "key": {
                              "type": "string",
                              "maxLength": 40
                            },
                            "skip": {
                              "type": "boolean",
                              "enum": [
                                true
                              ]
                            }
                          },
                          "required": [
                            "key",
                            "skip"
                          ],
                          "additionalProperties": false
                        }
                      ]
                    },
                    "minItems": 1,
                    "maxItems": 50
                  }
                },
                "required": [
                  "accounts"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Importado o en cola",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BankStatement"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/statements/{statementId}/undo": {
      "post": {
        "operationId": "undoBankStatement",
        "tags": [
          "bank"
        ],
        "summary": "Quitar los movimientos que trajo un extracto (si ninguno está conciliado)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:reconcile",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "statementId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Deshecho",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BankStatement"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/bank/connections": {
      "get": {
        "operationId": "listBankConnections",
        "tags": [
          "bank"
        ],
        "summary": "Conexiones con el banco a través del agregador (PSD2)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "bank:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Conexiones",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/BankConnection"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/verifactu/status": {
      "get": {
        "operationId": "getVerifactuStatus",
        "tags": [
          "verifactu"
        ],
        "summary": "Estado del envío a la AEAT: instalación, registros por estado, pendientes e incidencia abierta",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Estado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerifactuStatus"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/verifactu/incidents": {
      "get": {
        "operationId": "listVerifactuIncidents",
        "tags": [
          "verifactu"
        ],
        "summary": "Incidencias de envío recientes",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Lista",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/VerifactuIncident"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/verifactu/events": {
      "get": {
        "operationId": "listVerifactuEvents",
        "tags": [
          "verifactu"
        ],
        "summary": "Registro de eventos de la instalación vigente, con la comprobación de su cadena",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Eventos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/VerifactuEvent"
                      }
                    },
                    "chainIntact": {
                      "type": "boolean"
                    },
                    "firstBroken": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "items",
                    "chainIntact",
                    "firstBroken"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/verifactu/records": {
      "get": {
        "operationId": "listVerifactuRecords",
        "tags": [
          "verifactu"
        ],
        "summary": "Registros de facturación de la instalación vigente (más recientes primero), con filtros",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            },
            "required": false,
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "maxLength": 512,
              "pattern": "^[A-Za-z0-9_-]+$"
            },
            "required": false,
            "name": "cursor",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "local",
                "pending",
                "sending",
                "sent",
                "accepted",
                "accepted_with_errors",
                "rejected"
              ]
            },
            "required": false,
            "name": "status",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "alta",
                "anulacion"
              ]
            },
            "required": false,
            "name": "kind",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "from",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "to",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Página",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/VerifactuRecord"
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "items",
                    "nextCursor"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/verifactu/records/{recordId}": {
      "get": {
        "operationId": "getVerifactuRecord",
        "tags": [
          "verifactu"
        ],
        "summary": "Detalle de un registro: XML, respuesta de la AEAT y qué hacer",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "invoices:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "recordId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Registro",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerifactuRecordDetail"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/verifactu/exports": {
      "post": {
        "operationId": "exportVerifactuRecords",
        "tags": [
          "verifactu"
        ],
        "summary": "Exportar los registros generados en un periodo: zip con el XML de cada uno y un índice. Queda auditado",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "export:run",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExportVerifactuRecords"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Zip",
            "content": {
              "application/zip": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/features": {
      "get": {
        "operationId": "getOrgFeatures",
        "tags": [
          "billing"
        ],
        "summary": "Funciones encendidas para la organización (C-03): navegación y pantallas nuevas",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "org:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Funciones encendidas",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrgFeatures"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/search": {
      "get": {
        "operationId": "searchOrg",
        "tags": [
          "search"
        ],
        "summary": "Busca en las facturas, presupuestos, albaranes, contactos, productos, gastos, activos y modelos de la organización (lo que el rol puede leer)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "org:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "minLength": 2,
              "maxLength": 80,
              "pattern": "^[^\\p{Cc}]*$/u",
              "description": "Texto, NIF, número de documento, importe o «303 3T 2026»"
            },
            "required": true,
            "description": "Texto, NIF, número de documento, importe o «303 3T 2026»",
            "name": "q",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Resultados agrupados por tipo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchResult"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/exports": {
      "get": {
        "operationId": "listOrganizationExports",
        "tags": [
          "organizations"
        ],
        "summary": "Exportaciones recientes de la organización",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "export:run",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Exportaciones",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/OrganizationExport"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "exportOrganization",
        "tags": [
          "organizations"
        ],
        "summary": "Pedir la exportación completa (zip con JSON, CSV, PDF de facturas y XML VERI*FACTU)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "export:run",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "202": {
            "description": "En preparación",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrganizationExport"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/exports/{exportId}/download": {
      "get": {
        "operationId": "downloadOrganizationExport",
        "tags": [
          "organizations"
        ],
        "summary": "Descargar una exportación terminada",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "export:run",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "exportId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Zip",
            "content": {
              "application/zip": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/webhooks": {
      "get": {
        "operationId": "listWebhooks",
        "tags": [
          "webhooks"
        ],
        "summary": "Destinos de webhooks y eventos disponibles",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "api:webhooks",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Destinos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookEndpoint"
                      }
                    },
                    "events": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "enum": [
                          "invoice.issued",
                          "invoice.paid",
                          "invoice.voided",
                          "verifactu.record.accepted",
                          "verifactu.record.rejected",
                          "purchase.created",
                          "tax_return.presented"
                        ]
                      }
                    }
                  },
                  "required": [
                    "items",
                    "events"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createWebhook",
        "tags": [
          "webhooks"
        ],
        "summary": "Crea un destino; el secreto de firma se devuelve solo esta vez",
        "description": "La dirección tiene que ser https, en el puerto 443 y resolver solo a direcciones públicas. Cada entrega lleva `Slaupy-Signature: t=<segundos>,v1=<HMAC-SHA256 hex de \"t.cuerpo\">`, `Slaupy-Event-Id` (el mismo en cada reintento: úsalo para no procesar dos veces) y `Slaupy-Event-Type`. Se reintenta con espera creciente durante unos tres días; un destino que falla durante 72 h seguidas se desactiva.",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "api:webhooks",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "url": "https://tienda.example.com/slaupy/webhooks",
                "description": "Marcar pedidos como facturados",
                "events": [
                  "invoice.issued",
                  "invoice.paid"
                ]
              },
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "maxLength": 2048,
                    "format": "uri"
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "events": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "invoice.issued",
                        "invoice.paid",
                        "invoice.voided",
                        "verifactu.record.accepted",
                        "verifactu.record.rejected",
                        "purchase.created",
                        "tax_return.presented"
                      ]
                    },
                    "minItems": 1,
                    "maxItems": 7
                  }
                },
                "required": [
                  "url",
                  "events"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Destino creado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpointWithSecret"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/webhooks/{endpointId}": {
      "patch": {
        "operationId": "updateWebhook",
        "tags": [
          "webhooks"
        ],
        "summary": "Cambia la dirección, los eventos o lo activa y desactiva",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "api:webhooks",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "endpointId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "maxLength": 2048,
                    "format": "uri"
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "events": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "invoice.issued",
                        "invoice.paid",
                        "invoice.voided",
                        "verifactu.record.accepted",
                        "verifactu.record.rejected",
                        "purchase.created",
                        "tax_return.presented"
                      ]
                    },
                    "minItems": 1,
                    "maxItems": 7
                  },
                  "enabled": {
                    "type": "boolean"
                  },
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "version"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Destino",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpoint"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteWebhook",
        "tags": [
          "webhooks"
        ],
        "summary": "Borra un destino, su secreto y su historial de entregas",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "api:webhooks",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "endpointId",
            "in": "path"
          }
        ],
        "responses": {
          "204": {
            "description": "Borrado"
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/webhooks/{endpointId}/rotate-secret": {
      "post": {
        "operationId": "rotateWebhookSecret",
        "tags": [
          "webhooks"
        ],
        "summary": "Cambia el secreto de firma; el anterior deja de usarse al momento",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "api:webhooks",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "endpointId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Secreto nuevo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpointWithSecret"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/webhooks/{endpointId}/deliveries": {
      "get": {
        "operationId": "listWebhookDeliveries",
        "tags": [
          "webhooks"
        ],
        "summary": "Últimas entregas del destino (30 días)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "api:webhooks",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "endpointId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Entregas",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookDelivery"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/webhooks/{endpointId}/deliveries/{deliveryId}/resend": {
      "post": {
        "operationId": "resendWebhookDelivery",
        "tags": [
          "webhooks"
        ],
        "summary": "Vuelve a enviar una entrega (mismo evento y mismo Slaupy-Event-Id)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "api:webhooks",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "endpointId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "deliveryId",
            "in": "path"
          }
        ],
        "responses": {
          "202": {
            "description": "Entrega en cola",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookDelivery"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/webhooks/{endpointId}/ping": {
      "post": {
        "operationId": "pingWebhook",
        "tags": [
          "webhooks"
        ],
        "summary": "Envía un evento de prueba `webhook.ping`",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "api:webhooks",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "endpointId",
            "in": "path"
          }
        ],
        "responses": {
          "202": {
            "description": "Entrega en cola",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookDelivery"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/receivables/overdue": {
      "get": {
        "operationId": "getReceivables",
        "tags": [
          "receivables"
        ],
        "summary": "Lo pendiente de cobro por antigüedad y por cliente, con la etiqueta de pago de cada uno",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "receivables:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Por cobrar",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receivables"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/contacts/{contactId}/payment-profile": {
      "get": {
        "operationId": "getPaymentProfile",
        "tags": [
          "receivables"
        ],
        "summary": "Cómo paga un cliente: etiqueta, días medios y las facturas que la explican",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "receivables:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "contactId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Perfil de pago",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentProfile"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/receivables/disputes/{invoiceId}": {
      "put": {
        "operationId": "markInvoiceDisputed",
        "tags": [
          "receivables"
        ],
        "summary": "Marca una factura en disputa: sale de la antigüedad, de la puntuación y de los recordatorios",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "receivables:manage",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 300
                  }
                },
                "required": [
                  "reason"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "En disputa",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "invoiceId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "reason": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "invoiceId",
                    "reason"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "clearInvoiceDispute",
        "tags": [
          "receivables"
        ],
        "summary": "Quita la marca de disputa",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "receivables:manage",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          }
        ],
        "responses": {
          "204": {
            "description": "Sin disputa"
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/receivables/reminders": {
      "get": {
        "operationId": "listPaymentReminders",
        "tags": [
          "receivables"
        ],
        "summary": "Recordatorios de pago: los propuestos y el historial",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "receivables:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "suggested",
                "sent",
                "dismissed",
                "cancelled"
              ]
            },
            "required": false,
            "name": "status",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "invoiceId",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Recordatorios",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PaymentReminder"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/receivables/reminders/{reminderId}": {
      "patch": {
        "operationId": "updatePaymentReminder",
        "tags": [
          "receivables"
        ],
        "summary": "Edita un recordatorio propuesto antes de aprobarlo",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "receivables:manage",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "reminderId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "to": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "maxLength": 254,
                      "format": "email"
                    },
                    "minItems": 1,
                    "maxItems": 5
                  },
                  "subject": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "pattern": "^[^\\p{Cc}]*$/u"
                  },
                  "body": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 4000,
                    "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Recordatorio",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentReminder"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/receivables/reminders/{reminderId}/dismiss": {
      "post": {
        "operationId": "dismissPaymentReminder",
        "tags": [
          "receivables"
        ],
        "summary": "Descarta un recordatorio propuesto",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "receivables:manage",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "reminderId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Descartado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentReminder"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/receivables/reminders/suggest": {
      "post": {
        "operationId": "suggestPaymentReminders",
        "tags": [
          "receivables"
        ],
        "summary": "Propone ahora los recordatorios que tocan hoy (no envía nada)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "receivables:manage",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Propuestos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "created": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "created"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/receivables/policy": {
      "get": {
        "operationId": "getDunningPolicy",
        "tags": [
          "receivables"
        ],
        "summary": "Cuándo se proponen los recordatorios (días tras el vencimiento)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "receivables:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Política",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DunningPolicy"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "updateDunningPolicy",
        "tags": [
          "receivables"
        ],
        "summary": "Cambia cuándo se proponen los recordatorios",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "receivables:manage",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "enabled": {
                    "type": "boolean"
                  },
                  "level1Days": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 365
                  },
                  "level2Days": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 365
                  },
                  "level3Days": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 365
                  }
                },
                "required": [
                  "enabled",
                  "level1Days",
                  "level2Days",
                  "level3Days"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Política",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DunningPolicy"
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/receivables/contacts/{contactId}/demand": {
      "get": {
        "operationId": "getPaymentDemandPdf",
        "tags": [
          "receivables"
        ],
        "summary": "Requerimiento formal de pago en PDF de las facturas vencidas de un cliente (para enviar o mandar por burofax)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "receivables:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "contactId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/receivables/contacts/{contactId}/monitorio-pack": {
      "get": {
        "operationId": "getMonitorioPack",
        "tags": [
          "receivables"
        ],
        "summary": "Paquete para reclamar la deuda de un cliente (ZIP): guía con fuentes oficiales, requerimiento, facturas, pasos y justificantes. Slaupy no presenta nada",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "receivables:manage",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "contactId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "ZIP",
            "content": {
              "application/zip": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/receivables/invoices/{invoiceId}/escalation": {
      "get": {
        "operationId": "getReceivableEscalation",
        "tags": [
          "receivables"
        ],
        "summary": "Pasos dados tras los recordatorios y aviso del artículo 80 de la Ley del IVA",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "receivables:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Escalado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReceivableEscalation"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "recordReceivableEscalation",
        "tags": [
          "receivables"
        ],
        "summary": "Anota un paso (requerimiento, burofax, monitorio o publicación del concurso en el BOE) con su fecha y su justificante; Slaupy no envía ni presenta nada",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "receivables:manage",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "invoiceId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "step": {
                    "type": "string",
                    "enum": [
                      "demand",
                      "burofax",
                      "monitorio",
                      "insolvency"
                    ]
                  },
                  "occurredOn": {
                    "type": "string"
                  },
                  "note": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "fileId": {
                    "type": "string",
                    "format": "uuid"
                  }
                },
                "required": [
                  "step",
                  "occurredOn"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Anotado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "step": {
                      "type": "string",
                      "enum": [
                        "demand",
                        "burofax",
                        "monitorio",
                        "insolvency"
                      ]
                    },
                    "occurredOn": {
                      "type": "string"
                    },
                    "note": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "fileId": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "uuid"
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "id",
                    "step",
                    "occurredOn",
                    "note",
                    "fileId",
                    "createdAt"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/close/{year}/{month}": {
      "get": {
        "operationId": "getMonthClose",
        "tags": [
          "close"
        ],
        "summary": "Lista de comprobación del cierre de un mes: qué falta por emitir, registrar, cobrar o conciliar",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 2000,
              "maximum": 2100
            },
            "required": true,
            "name": "year",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 12
            },
            "required": true,
            "name": "month",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Lista del mes",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MonthChecklist"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/close/{year}/{month}/complete": {
      "post": {
        "operationId": "completeMonthClose",
        "tags": [
          "close"
        ],
        "summary": "Da el mes por revisado (no bloquea nada: el bloqueo legal es el cierre de periodo)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:file",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 2000,
              "maximum": 2100
            },
            "required": true,
            "name": "year",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 12
            },
            "required": true,
            "name": "month",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Mes revisado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MonthChecklist"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/treasury/forecast": {
      "get": {
        "operationId": "getTreasuryForecast",
        "tags": [
          "treasury"
        ],
        "summary": "Previsión de tesorería: saldo por semana, cifras a 30, 60 y 90 días y el primer día en negativo",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 7,
              "maximum": 90,
              "default": 90
            },
            "required": false,
            "name": "horizon",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1"
              ],
              "default": "0"
            },
            "required": false,
            "name": "quotes",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Previsión",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TreasuryForecast"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/orgs/{orgId}/treasury/settings": {
      "get": {
        "operationId": "getTreasurySettings",
        "tags": [
          "treasury"
        ],
        "summary": "Ajustes de la previsión: saldo inicial, cuota de autónomos, gastos periódicos y ajustes",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-permission": "tax:read",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "orgId",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Ajustes",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TreasurySettings"
                }
              }
            }
          },
          "401": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Error (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "example": "urn:slaupy:problem:validation_failed"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "code": {
            "type": "string",
            "enum": [
              "validation_failed",
              "malformed_json",
              "unauthenticated",
              "forbidden",
              "not_found",
              "method_not_allowed",
              "version_conflict",
              "payload_too_large",
              "unsupported_media_type",
              "rate_limited",
              "app_update_required",
              "captcha_failed",
              "waitlist_token_invalid",
              "invalid_credentials",
              "email_not_verified",
              "password_too_short",
              "password_too_long",
              "password_compromised",
              "password_already_set",
              "auth_token_invalid",
              "account_locked",
              "terms_not_accepted",
              "agreement_not_accepted",
              "consent_version_outdated",
              "unsubscribe_link_invalid",
              "preferences_link_invalid",
              "preferences_link_grant_forbidden",
              "unsubscribe_link_expired",
              "auth_failed",
              "csrf_origin_invalid",
              "provider_not_configured",
              "social_link_failed",
              "social_token_invalid",
              "reauthentication_required",
              "two_factor_code_invalid",
              "two_factor_locked",
              "two_factor_already_enabled",
              "two_factor_not_enabled",
              "two_factor_required",
              "invitation_invalid",
              "invitation_email_mismatch",
              "last_owner",
              "slug_taken",
              "already_member",
              "tax_territory_not_supported",
              "too_many_invitations",
              "idempotency_key_required",
              "idempotency_key_reused",
              "idempotency_in_progress",
              "file_type_not_allowed",
              "file_upload_mismatch",
              "file_not_uploaded",
              "file_not_ready",
              "storage_quota_exceeded",
              "contact_in_use",
              "product_in_use",
              "series_inactive",
              "series_number_invalid",
              "series_code_taken",
              "series_in_use",
              "invoice_not_draft",
              "tax_rate_not_in_force",
              "invoice_not_issuable",
              "invoice_not_issued",
              "invoice_voided",
              "rectify_mixed_customers",
              "rectify_type_mismatch",
              "invoice_has_payments",
              "invoice_rectified",
              "period_closed",
              "period_not_closable",
              "period_not_closed",
              "payment_exceeds_pending",
              "quote_locked",
              "quote_rejected",
              "delivery_note_invoiced",
              "delivery_note_not_delivered",
              "delivery_note_mixed_customers",
              "delivery_note_mixed_delivery_countries",
              "quote_not_accepted",
              "certificate_unreadable",
              "certificate_password",
              "certificate_no_key",
              "certificate_key_mismatch",
              "certificate_expired",
              "certificate_not_yet_valid",
              "certificate_no_tax_id",
              "certificate_issuer_not_accepted",
              "certificate_tax_id_mismatch",
              "verifactu_record_superseded",
              "verifactu_record_not_correctable",
              "verifactu_not_configured",
              "verifactu_excluded",
              "verifactu_profile_incomplete",
              "verifactu_representation_unavailable",
              "verifactu_already_active",
              "verifactu_producer_missing",
              "verifactu_keys_missing",
              "purchase_invalid",
              "purchase_not_draft",
              "purchase_not_confirmed",
              "purchase_has_payments",
              "purchase_in_payment_batch",
              "ai_unavailable",
              "ai_disabled",
              "ai_quota_exceeded",
              "ai_trial_quota_exceeded",
              "ai_paused",
              "ai_reading_needs_person",
              "vat_id_not_eu",
              "coefficient_out_of_range",
              "asset_disposed",
              "tax_return_already_presented",
              "tax_return_blocked",
              "tax_return_draft_exists",
              "tax_return_profile_incomplete",
              "model_period_unsupported",
              "tax_settings_locked",
              "logo_invalid",
              "logo_unsafe",
              "logo_too_large",
              "slaupy_mark_required",
              "plan_members_limit",
              "plan_sales_channels_limit",
              "subscription_required",
              "billing_unavailable",
              "plan_not_available",
              "already_subscribed",
              "not_subscribed",
              "refund_guarantee_used",
              "refund_guarantee_expired",
              "refund_guarantee_unavailable",
              "deletion_pending",
              "deletion_not_pending",
              "subscription_active",
              "import_file_unreadable",
              "import_file_encrypted",
              "import_file_too_large",
              "import_too_many_rows",
              "import_empty",
              "import_mapping_invalid",
              "import_next_number_invalid",
              "import_not_pending",
              "import_not_done",
              "import_undo_blocked",
              "sales_report_unrecognized",
              "sales_channel_archived",
              "payment_batch_not_draft",
              "payment_batch_not_approved",
              "payment_batch_iban_invalid",
              "payment_batch_iban_missing",
              "payment_batch_iban_pending",
              "payment_batch_purchase_unavailable",
              "bank_statement_invalid",
              "bank_statement_unreadable",
              "bank_statement_columns_unknown",
              "bank_statement_balance_mismatch",
              "bank_statement_empty",
              "bank_statement_too_large",
              "bank_statement_not_pending",
              "bank_statement_not_done",
              "bank_statement_undo_blocked",
              "bank_rule_proposal_missing",
              "bank_statement_accounts_invalid",
              "bank_account_iban_taken",
              "bank_connection_not_syncable",
              "demo_restricted",
              "demo_unavailable",
              "staff_two_factor_required",
              "staff_not_in_trial",
              "support_access_inactive",
              "feedback_limit_reached",
              "help_request_limit_reached",
              "feedback_not_fixed",
              "feedback_theme_title_taken",
              "feedback_theme_closed",
              "feedback_theme_issue_exists",
              "roadmap_copy_forbidden",
              "roadmap_slug_taken",
              "promo_code_invalid",
              "promo_code_used",
              "promo_not_in_trial",
              "referral_code_invalid",
              "referral_not_eligible",
              "promo_campaign_exists",
              "promo_activation_script",
              "feedback_context_forbidden",
              "accounting_chart_missing",
              "accounting_chart_exists",
              "account_code_invalid",
              "account_code_taken",
              "account_not_postable",
              "entry_unbalanced",
              "entry_not_draft",
              "entry_not_posted",
              "entry_not_reversible",
              "entry_already_reversed",
              "fiscal_year_invalid",
              "fiscal_year_missing",
              "fiscal_year_closed",
              "fiscal_year_not_closable",
              "fiscal_year_not_closed",
              "fiscal_year_not_reopenable",
              "fiscal_year_closing",
              "year_end_run_active",
              "bank_transaction_not_pending",
              "bank_transaction_not_reconciled",
              "bank_transaction_currency",
              "reconciliation_amount_invalid",
              "approval_required",
              "approval_not_pending",
              "notification_pending",
              "approval_self",
              "payment_batch_self",
              "company_only",
              "accounting_export_account_length",
              "accounting_export_no_program",
              "report_too_large",
              "api_key_limit_reached",
              "webhook_limit_reached",
              "oauth_request_invalid",
              "ai_connection_limit_reached",
              "webhook_url_not_allowed",
              "firm_link_exists",
              "firm_link_state",
              "firm_last_partner",
              "firm_advisor_required",
              "tax_code_not_for_territory",
              "tax_return_no_file",
              "firm_review_state",
              "firm_review_approved",
              "firm_batch_too_large",
              "internal_error",
              "service_unavailable"
            ]
          },
          "detail": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FieldError"
            }
          },
          "current": {
            "description": "Con version_conflict: el recurso tal como está ahora"
          },
          "requestId": {
            "type": "string"
          }
        },
        "required": [
          "type",
          "title",
          "status",
          "code",
          "requestId"
        ]
      },
      "FieldError": {
        "type": "object",
        "properties": {
          "in": {
            "type": "string",
            "enum": [
              "body",
              "query",
              "path",
              "header",
              "cookie"
            ]
          },
          "path": {
            "type": "string",
            "example": "lines.0.quantity"
          },
          "code": {
            "type": "string",
            "example": "too_small"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "in",
          "path",
          "code",
          "message"
        ]
      },
      "MyOrganization": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Organization"
          },
          {
            "type": "object",
            "properties": {
              "role": {
                "type": "string",
                "enum": [
                  "owner",
                  "admin",
                  "accountant",
                  "sales",
                  "readonly",
                  "advisor",
                  "approver"
                ]
              },
              "permissions": {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "org:read",
                    "members:read",
                    "invoices:read",
                    "invoices:write",
                    "invoices:issue",
                    "invoices:void",
                    "purchases:read",
                    "purchases:write",
                    "purchases:pay",
                    "tax:read",
                    "tax:file",
                    "settings:write",
                    "members:manage",
                    "billing:read",
                    "billing:manage",
                    "verifactu:manage",
                    "apikeys:manage",
                    "audit:read",
                    "export:run",
                    "files:read",
                    "files:write",
                    "bank:read",
                    "bank:reconcile",
                    "bank:manage",
                    "accounting:read",
                    "accounting:write",
                    "accounting:close",
                    "receivables:read",
                    "receivables:manage",
                    "firm:read",
                    "firm:manage",
                    "api:connections",
                    "api:webhooks",
                    "channels:read",
                    "channels:manage",
                    "org:leave",
                    "review:write"
                  ]
                }
              },
              "firmDelegations": {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "confirm_supplier_iban"
                  ]
                },
                "description": "Lo que esta organización permite además al despacho de quien trabaja como despacho"
              }
            },
            "required": [
              "role",
              "permissions"
            ]
          }
        ]
      },
      "Organization": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "autonomo",
              "sociedad"
            ]
          },
          "country": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "timezone": {
            "type": "string"
          },
          "locale": {
            "type": "string"
          },
          "taxTerritory": {
            "type": "string",
            "enum": [
              "es_comun",
              "es_canarias",
              "es_ceuta",
              "es_melilla",
              "es_alava",
              "es_bizkaia",
              "es_gipuzkoa",
              "es_navarra"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "trial",
              "active",
              "past_due",
              "read_only",
              "cancelled",
              "deleting"
            ]
          },
          "trialEndsAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "requireTwoFactor": {
            "type": "boolean"
          },
          "version": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "slug",
          "name",
          "type",
          "country",
          "currency",
          "timezone",
          "locale",
          "taxTerritory",
          "status",
          "trialEndsAt",
          "requireTwoFactor",
          "version",
          "createdAt"
        ]
      },
      "TaxProfile": {
        "type": "object",
        "properties": {
          "legalName": {
            "type": [
              "string",
              "null"
            ]
          },
          "tradeName": {
            "type": [
              "string",
              "null"
            ]
          },
          "taxIdType": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "nif",
              "nie",
              "cif",
              "vat_eu",
              "other",
              null
            ]
          },
          "taxId": {
            "type": [
              "string",
              "null"
            ]
          },
          "line1": {
            "type": [
              "string",
              "null"
            ]
          },
          "line2": {
            "type": [
              "string",
              "null"
            ]
          },
          "postalCode": {
            "type": [
              "string",
              "null"
            ]
          },
          "city": {
            "type": [
              "string",
              "null"
            ]
          },
          "province": {
            "type": [
              "string",
              "null"
            ]
          },
          "addressCountry": {
            "type": [
              "string",
              "null"
            ]
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          },
          "iban": {
            "type": [
              "string",
              "null"
            ]
          },
          "version": {
            "type": "integer"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "legalName",
          "tradeName",
          "taxIdType",
          "taxId",
          "line1",
          "line2",
          "postalCode",
          "city",
          "province",
          "addressCountry",
          "email",
          "phone",
          "iban",
          "version",
          "updatedAt"
        ]
      },
      "Onboarding": {
        "type": "object",
        "properties": {
          "applies": {
            "type": "boolean"
          },
          "step": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "fiscal",
              "company",
              "series",
              "logo",
              "invoice",
              null
            ]
          },
          "done": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "fiscal",
                "company",
                "series",
                "logo",
                "invoice"
              ]
            }
          },
          "skipped": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "fiscal",
                "company",
                "series",
                "logo",
                "invoice"
              ]
            }
          },
          "completedAt": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "applies",
          "step",
          "done",
          "skipped",
          "completedAt"
        ]
      },
      "File": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "attachment",
              "logo",
              "expense",
              "import",
              "bank_statement",
              "document"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "ready",
              "rejected"
            ]
          },
          "originalName": {
            "type": "string"
          },
          "mime": {
            "type": [
              "string",
              "null"
            ]
          },
          "sizeBytes": {
            "type": [
              "integer",
              "null"
            ]
          },
          "sha256": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "completedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "kind",
          "status",
          "originalName",
          "mime",
          "sizeBytes",
          "sha256",
          "createdAt",
          "completedAt"
        ]
      },
      "CreateFile": {
        "type": "object",
        "properties": {
          "fileName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "mime": {
            "type": "string",
            "enum": [
              "application/pdf",
              "image/jpeg",
              "image/png",
              "image/heic",
              "image/webp",
              "application/xml",
              "image/svg+xml",
              "text/csv",
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
              "application/vnd.ms-excel",
              "application/vnd.oasis.opendocument.spreadsheet"
            ]
          },
          "size": {
            "type": "integer",
            "minimum": 1,
            "maximum": 15728640
          },
          "sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "kind": {
            "type": "string",
            "enum": [
              "attachment",
              "logo",
              "expense",
              "import",
              "bank_statement"
            ],
            "default": "attachment"
          }
        },
        "required": [
          "fileName",
          "mime",
          "size"
        ],
        "additionalProperties": false
      },
      "ContactPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Contact"
            }
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "items",
          "nextCursor"
        ]
      },
      "Contact": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "company",
              "individual"
            ]
          },
          "name": {
            "type": "string"
          },
          "tradeName": {
            "type": [
              "string",
              "null"
            ]
          },
          "isCustomer": {
            "type": "boolean"
          },
          "isSupplier": {
            "type": "boolean"
          },
          "taxIdType": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "nif",
              "vat_eu",
              "passport",
              "foreign_id",
              "residence_cert",
              "other",
              null
            ]
          },
          "taxId": {
            "type": [
              "string",
              "null"
            ]
          },
          "taxIdCountry": {
            "type": [
              "string",
              "null"
            ]
          },
          "viesStatus": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "valid",
              "invalid",
              "unavailable",
              null
            ]
          },
          "viesCheckedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          },
          "line1": {
            "type": [
              "string",
              "null"
            ]
          },
          "line2": {
            "type": [
              "string",
              "null"
            ]
          },
          "postalCode": {
            "type": [
              "string",
              "null"
            ]
          },
          "city": {
            "type": [
              "string",
              "null"
            ]
          },
          "province": {
            "type": [
              "string",
              "null"
            ]
          },
          "addressCountry": {
            "type": [
              "string",
              "null"
            ]
          },
          "paymentTermsDays": {
            "type": [
              "integer",
              "null"
            ]
          },
          "supplierIban": {
            "type": [
              "string",
              "null"
            ]
          },
          "supplierIbanPending": {
            "type": "boolean"
          },
          "supplierIbanPrevious": {
            "type": [
              "string",
              "null"
            ]
          },
          "defaultWithholdingRate": {
            "type": [
              "string",
              "null"
            ]
          },
          "equivalenceSurcharge": {
            "type": "boolean"
          },
          "rentalProperty": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "cadastralRef": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "situation": {
                "type": "string",
                "enum": [
                  "1",
                  "2",
                  "3",
                  "4"
                ]
              },
              "address": {
                "type": "string"
              },
              "postalCode": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "municipality": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "cadastralRef",
              "situation",
              "address",
              "postalCode",
              "municipality"
            ]
          },
          "documentLocale": {
            "type": "string",
            "enum": [
              "es",
              "en"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "archivedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "version": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "kind",
          "name",
          "tradeName",
          "isCustomer",
          "isSupplier",
          "taxIdType",
          "taxId",
          "taxIdCountry",
          "viesStatus",
          "viesCheckedAt",
          "email",
          "phone",
          "line1",
          "line2",
          "postalCode",
          "city",
          "province",
          "addressCountry",
          "paymentTermsDays",
          "supplierIban",
          "supplierIbanPending",
          "supplierIbanPrevious",
          "defaultWithholdingRate",
          "equivalenceSurcharge",
          "rentalProperty",
          "documentLocale",
          "notes",
          "archivedAt",
          "version",
          "createdAt",
          "updatedAt"
        ]
      },
      "ViesCheck": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "valid",
              "invalid",
              "unavailable"
            ]
          },
          "checkedAt": {
            "type": "string",
            "format": "date-time"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "address": {
            "type": [
              "string",
              "null"
            ]
          },
          "requestIdentifier": {
            "type": [
              "string",
              "null"
            ]
          },
          "cached": {
            "type": "boolean"
          },
          "reason": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "status",
          "checkedAt",
          "name",
          "address",
          "requestIdentifier",
          "cached",
          "reason"
        ]
      },
      "ProductPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Product"
            }
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "items",
          "nextCursor"
        ]
      },
      "Product": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "kind": {
            "type": "string",
            "enum": [
              "good",
              "service"
            ]
          },
          "unitPrice": {
            "type": "string",
            "description": "Precio unitario sin impuestos, decimal",
            "example": "49.9"
          },
          "taxCode": {
            "type": "string"
          },
          "unit": {
            "type": [
              "string",
              "null"
            ]
          },
          "sku": {
            "type": [
              "string",
              "null"
            ]
          },
          "archivedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "version": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "name",
          "description",
          "kind",
          "unitPrice",
          "taxCode",
          "unit",
          "sku",
          "archivedAt",
          "version",
          "createdAt",
          "updatedAt"
        ]
      },
      "InvoiceSeries": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "code": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "ordinaria",
              "rectificativa",
              "simplificada"
            ]
          },
          "format": {
            "type": "string"
          },
          "yearlyReset": {
            "type": "boolean"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "active": {
            "type": "boolean"
          },
          "inUse": {
            "type": "boolean",
            "description": "Ya ha numerado facturas: el formato y el código no cambian"
          },
          "nextNumber": {
            "type": "string",
            "description": "Cómo será el próximo número este año",
            "example": "A27-00001"
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "code",
          "kind",
          "format",
          "yearlyReset",
          "description",
          "active",
          "inUse",
          "nextNumber",
          "version"
        ]
      },
      "InvoicePage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InvoiceSummary"
            }
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          },
          "totals": {
            "$ref": "#/components/schemas/InvoiceListTotals"
          }
        },
        "required": [
          "items",
          "nextCursor",
          "totals"
        ]
      },
      "InvoiceSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "issued",
              "voided"
            ]
          },
          "origin": {
            "type": "string",
            "enum": [
              "native",
              "imported",
              "external"
            ]
          },
          "type": {
            "type": "string",
            "enum": [
              "F1",
              "F2",
              "F3",
              "R1",
              "R2",
              "R3",
              "R4",
              "R5"
            ]
          },
          "seriesId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "fullNumber": {
            "type": [
              "string",
              "null"
            ]
          },
          "issueDate": {
            "type": [
              "string",
              "null"
            ]
          },
          "dueDate": {
            "type": [
              "string",
              "null"
            ]
          },
          "contactId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "customerName": {
            "type": [
              "string",
              "null"
            ]
          },
          "customerTaxId": {
            "type": [
              "string",
              "null"
            ],
            "description": "NIF del cliente: el de la factura emitida o el de su ficha en un borrador"
          },
          "currency": {
            "type": "string"
          },
          "subtotalMinor": {
            "type": "integer",
            "description": "Base imponible"
          },
          "taxMinor": {
            "type": "integer",
            "description": "Cuota de IVA más recargo de equivalencia"
          },
          "withholdingMinor": {
            "type": "integer",
            "description": "Retención de IRPF"
          },
          "totalMinor": {
            "type": "integer"
          },
          "payableMinor": {
            "type": "integer"
          },
          "paidMinor": {
            "type": "integer"
          },
          "paymentStatus": {
            "type": "string",
            "enum": [
              "unpaid",
              "partial",
              "paid"
            ]
          },
          "overdue": {
            "type": "boolean"
          },
          "vfStatus": {
            "type": [
              "string",
              "null"
            ]
          },
          "sentAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "version": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "status",
          "origin",
          "type",
          "seriesId",
          "fullNumber",
          "issueDate",
          "dueDate",
          "contactId",
          "customerName",
          "customerTaxId",
          "currency",
          "subtotalMinor",
          "taxMinor",
          "withholdingMinor",
          "totalMinor",
          "payableMinor",
          "paidMinor",
          "paymentStatus",
          "overdue",
          "vfStatus",
          "sentAt",
          "version",
          "createdAt",
          "updatedAt"
        ]
      },
      "InvoiceListTotals": {
        "type": "object",
        "properties": {
          "count": {
            "type": "integer"
          },
          "totalMinor": {
            "type": "integer"
          },
          "payableMinor": {
            "type": "integer"
          },
          "paidMinor": {
            "type": "integer"
          },
          "pendingMinor": {
            "type": "integer"
          },
          "subtotalMinor": {
            "type": "integer",
            "description": "Base imponible de lo filtrado"
          },
          "taxMinor": {
            "type": "integer",
            "description": "IVA y recargo de lo filtrado"
          },
          "withholdingMinor": {
            "type": "integer",
            "description": "Retenciones de lo filtrado"
          },
          "overdueMinor": {
            "type": "integer",
            "description": "Lo vencido y sin cobrar de lo filtrado"
          },
          "states": {
            "type": "object",
            "properties": {
              "all": {
                "type": "integer"
              },
              "draft": {
                "type": "integer"
              },
              "pending": {
                "type": "integer"
              },
              "overdue": {
                "type": "integer"
              },
              "paid": {
                "type": "integer"
              }
            },
            "required": [
              "all",
              "draft",
              "pending",
              "overdue",
              "paid"
            ],
            "description": "Recuento por estado con los mismos filtros salvo el de estado y cobro: los contadores del filtro de estado."
          }
        },
        "required": [
          "count",
          "totalMinor",
          "payableMinor",
          "paidMinor",
          "pendingMinor",
          "subtotalMinor",
          "taxMinor",
          "withholdingMinor",
          "overdueMinor",
          "states"
        ]
      },
      "Invoice": {
        "allOf": [
          {
            "$ref": "#/components/schemas/InvoiceSummary"
          },
          {
            "type": "object",
            "properties": {
              "subtotalMinor": {
                "type": "integer"
              },
              "taxMinor": {
                "type": "integer"
              },
              "withholdingMinor": {
                "type": "integer"
              },
              "number": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "fiscalYear": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "operationDate": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "customer": {
                "$ref": "#/components/schemas/InvoiceParty"
              },
              "issuer": {
                "$ref": "#/components/schemas/InvoiceParty"
              },
              "globalDiscountPct": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "surchargeMinor": {
                "type": "integer"
              },
              "rectificationMode": {
                "type": [
                  "string",
                  "null"
                ],
                "enum": [
                  "difference",
                  "substitution",
                  null
                ]
              },
              "rectificationReason": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "substitutedBaseMinor": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "substitutedTaxMinor": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "rectifies": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "fullNumber": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "issueDate": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "id",
                    "fullNumber",
                    "issueDate"
                  ]
                },
                "description": "Facturas que rectifica"
              },
              "description": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "notes": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "paymentMethod": {
                "type": [
                  "string",
                  "null"
                ],
                "enum": [
                  "transfer",
                  "card",
                  "cash",
                  "direct_debit",
                  "bizum",
                  "other",
                  null
                ]
              },
              "paymentDetails": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "documentLocale": {
                "type": "string",
                "enum": [
                  "es",
                  "en"
                ]
              },
              "deliveryCountry": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "País de entrega de los bienes (ISO 3166-1, o ES-CN, ES-CE, ES-ML para Canarias, Ceuta y Melilla). En un borrador, null es el país del cliente; al emitir se guarda el que corresponda"
              },
              "issuedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "voidedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "voidReason": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "hasPdf": {
                "type": "boolean"
              },
              "lines": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/InvoiceLine"
                }
              },
              "taxLines": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/InvoiceTaxLine"
                }
              }
            },
            "required": [
              "number",
              "fiscalYear",
              "operationDate",
              "customer",
              "issuer",
              "globalDiscountPct",
              "surchargeMinor",
              "rectificationMode",
              "rectificationReason",
              "substitutedBaseMinor",
              "substitutedTaxMinor",
              "rectifies",
              "description",
              "notes",
              "paymentMethod",
              "paymentDetails",
              "documentLocale",
              "deliveryCountry",
              "issuedAt",
              "voidedAt",
              "voidReason",
              "hasPdf",
              "lines",
              "taxLines"
            ]
          }
        ]
      },
      "InvoiceParty": {
        "type": [
          "object",
          "null"
        ],
        "properties": {
          "contactId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "taxId": {
            "type": [
              "string",
              "null"
            ]
          },
          "taxIdType": {
            "type": [
              "string",
              "null"
            ]
          },
          "taxIdCountry": {
            "type": [
              "string",
              "null"
            ]
          },
          "address": {
            "type": [
              "string",
              "null"
            ]
          },
          "country": {
            "type": [
              "string",
              "null"
            ],
            "description": "País de la dirección (ISO 3166-1)"
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "contactId",
          "name",
          "taxId",
          "taxIdType",
          "taxIdCountry",
          "address",
          "country",
          "email"
        ]
      },
      "InvoiceLine": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "position": {
            "type": "integer"
          },
          "productId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "quantity": {
            "type": "string"
          },
          "unitPrice": {
            "type": "string"
          },
          "discountPct": {
            "type": [
              "string",
              "null"
            ]
          },
          "unit": {
            "type": [
              "string",
              "null"
            ]
          },
          "baseMinor": {
            "type": "integer"
          },
          "taxCode": {
            "type": "string"
          },
          "taxKind": {
            "type": "string"
          },
          "taxRate": {
            "type": "string"
          },
          "surchargeRate": {
            "type": "string"
          },
          "operationClass": {
            "type": "string"
          },
          "exemptionCause": {
            "type": [
              "string",
              "null"
            ]
          },
          "regimeKey": {
            "type": "string"
          },
          "withholdingRate": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "position",
          "productId",
          "description",
          "quantity",
          "unitPrice",
          "discountPct",
          "unit",
          "baseMinor",
          "taxCode",
          "taxKind",
          "taxRate",
          "surchargeRate",
          "operationClass",
          "exemptionCause",
          "regimeKey",
          "withholdingRate"
        ]
      },
      "InvoiceTaxLine": {
        "type": "object",
        "properties": {
          "taxKind": {
            "type": "string"
          },
          "taxRate": {
            "type": "string"
          },
          "surchargeRate": {
            "type": "string"
          },
          "operationClass": {
            "type": "string"
          },
          "exemptionCause": {
            "type": [
              "string",
              "null"
            ]
          },
          "regimeKey": {
            "type": "string"
          },
          "baseMinor": {
            "type": "integer"
          },
          "taxMinor": {
            "type": "integer"
          },
          "surchargeMinor": {
            "type": "integer"
          }
        },
        "required": [
          "taxKind",
          "taxRate",
          "surchargeRate",
          "operationClass",
          "exemptionCause",
          "regimeKey",
          "baseMinor",
          "taxMinor",
          "surchargeMinor"
        ]
      },
      "InvoiceTotalsPreview": {
        "type": "object",
        "properties": {
          "lines": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "position": {
                  "type": "integer"
                },
                "baseMinor": {
                  "type": "integer"
                }
              },
              "required": [
                "position",
                "baseMinor"
              ]
            }
          },
          "taxLines": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InvoiceTaxLine"
            }
          },
          "subtotalMinor": {
            "type": "integer"
          },
          "globalDiscountMinor": {
            "type": "integer"
          },
          "taxMinor": {
            "type": "integer"
          },
          "surchargeMinor": {
            "type": "integer"
          },
          "withholdingMinor": {
            "type": "integer"
          },
          "totalMinor": {
            "type": "integer"
          },
          "payableMinor": {
            "type": "integer"
          }
        },
        "required": [
          "lines",
          "taxLines",
          "subtotalMinor",
          "globalDiscountMinor",
          "taxMinor",
          "surchargeMinor",
          "withholdingMinor",
          "totalMinor",
          "payableMinor"
        ]
      },
      "IssueInvoice": {
        "type": "object",
        "properties": {
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "issueDate": {
            "type": [
              "string",
              "null"
            ]
          },
          "simplifiedSpecialCase": {
            "type": "boolean"
          }
        },
        "required": [
          "version"
        ],
        "additionalProperties": false
      },
      "RectifyInvoice": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "R1",
              "R2",
              "R3",
              "R4",
              "R5",
              "F3"
            ],
            "default": "R4"
          },
          "mode": {
            "type": "string",
            "enum": [
              "difference",
              "substitution"
            ],
            "default": "difference"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 500
          },
          "helper": {
            "type": "string",
            "enum": [
              "full_credit",
              "correct_data",
              "blank"
            ],
            "default": "blank"
          },
          "alsoRectifies": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 50,
            "default": []
          },
          "lines": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "productId": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "description": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "maxLength": 1000,
                  "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                },
                "quantity": {
                  "type": "string"
                },
                "unitPrice": {
                  "type": "string"
                },
                "discountPct": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "taxCode": {
                  "type": "string"
                },
                "exemptionCause": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "enum": [
                    "E1",
                    "E2",
                    "E3",
                    "E4",
                    "E5",
                    "E6",
                    null
                  ]
                },
                "withholdingRate": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "unit": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "maxLength": 20,
                  "pattern": "^[^\\p{Cc}]*$/u"
                }
              },
              "required": [
                "quantity",
                "unitPrice",
                "taxCode"
              ],
              "additionalProperties": false
            },
            "maxItems": 500
          }
        },
        "required": [
          "reason"
        ],
        "additionalProperties": false
      },
      "VoidInvoice": {
        "type": "object",
        "properties": {
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 3,
            "maxLength": 500
          }
        },
        "required": [
          "version",
          "reason"
        ],
        "additionalProperties": false
      },
      "InvoicePayments": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Payment"
            }
          },
          "paidMinor": {
            "type": "integer"
          },
          "pendingMinor": {
            "type": "integer"
          },
          "paymentStatus": {
            "type": "string"
          },
          "invoiceVersion": {
            "type": "integer"
          }
        },
        "required": [
          "items",
          "paidMinor",
          "pendingMinor",
          "paymentStatus",
          "invoiceVersion"
        ]
      },
      "Payment": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "invoiceId": {
            "type": "string",
            "format": "uuid"
          },
          "paidOn": {
            "type": "string"
          },
          "amountMinor": {
            "type": "integer"
          },
          "method": {
            "type": "string",
            "enum": [
              "transfer",
              "card",
              "cash",
              "direct_debit",
              "bizum",
              "other"
            ]
          },
          "reference": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "version": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "invoiceId",
          "paidOn",
          "amountMinor",
          "method",
          "reference",
          "notes",
          "version",
          "createdAt"
        ]
      },
      "DeliveryNotePage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DeliveryNote"
            }
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "items",
          "nextCursor"
        ]
      },
      "DeliveryNote": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "delivered",
              "invoiced",
              "cancelled"
            ]
          },
          "fullNumber": {
            "type": "string"
          },
          "deliveryDate": {
            "type": "string"
          },
          "contactId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "customerName": {
            "type": [
              "string",
              "null"
            ]
          },
          "customerTaxId": {
            "type": [
              "string",
              "null"
            ]
          },
          "quoteId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "valued": {
            "type": "boolean"
          },
          "currency": {
            "type": "string"
          },
          "subtotalMinor": {
            "type": "integer"
          },
          "taxMinor": {
            "type": "integer"
          },
          "totalMinor": {
            "type": "integer"
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "documentLocale": {
            "type": "string",
            "enum": [
              "es",
              "en"
            ]
          },
          "deliveryCountry": {
            "type": [
              "string",
              "null"
            ],
            "description": "País de entrega de los bienes (ISO 3166-1, o ES-CN, ES-CE, ES-ML); null es el país del cliente. Pasa a la factura"
          },
          "invoiceId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "invoiceNumber": {
            "type": [
              "string",
              "null"
            ]
          },
          "version": {
            "type": "integer"
          },
          "lines": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "position": {
                  "type": "integer"
                },
                "productId": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid"
                },
                "description": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "quantity": {
                  "type": "string"
                },
                "unitPrice": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "discountPct": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "unit": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "baseMinor": {
                  "type": "integer"
                },
                "taxCode": {
                  "type": "string"
                },
                "withholdingRate": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "position",
                "productId",
                "description",
                "quantity",
                "unitPrice",
                "discountPct",
                "unit",
                "baseMinor",
                "taxCode",
                "withholdingRate"
              ]
            }
          }
        },
        "required": [
          "id",
          "status",
          "fullNumber",
          "deliveryDate",
          "contactId",
          "customerName",
          "customerTaxId",
          "quoteId",
          "valued",
          "currency",
          "subtotalMinor",
          "taxMinor",
          "totalMinor",
          "notes",
          "documentLocale",
          "deliveryCountry",
          "invoiceId",
          "invoiceNumber",
          "version",
          "lines"
        ]
      },
      "DeliveryNotesInvoiced": {
        "type": "object",
        "properties": {
          "invoiceId": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": [
          "invoiceId"
        ]
      },
      "DocumentStyles": {
        "type": "object",
        "properties": {
          "default": {
            "$ref": "#/components/schemas/DocumentStyle"
          },
          "series": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentStyle"
            }
          },
          "logo": {
            "$ref": "#/components/schemas/DocumentLogo"
          },
          "canHideSlaupyMark": {
            "type": "boolean"
          }
        },
        "required": [
          "default",
          "series",
          "logo",
          "canHideSlaupyMark"
        ]
      },
      "DocumentStyle": {
        "type": "object",
        "properties": {
          "id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Null mientras se usa el estilo por defecto"
          },
          "seriesId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "layout": {
            "type": "string",
            "enum": [
              "classic",
              "modern",
              "compact"
            ]
          },
          "accentColor": {
            "type": [
              "string",
              "null"
            ]
          },
          "font": {
            "type": "string",
            "enum": [
              "instrument",
              "source-sans",
              "newsreader"
            ]
          },
          "footerText": {
            "type": [
              "string",
              "null"
            ]
          },
          "paymentText": {
            "type": [
              "string",
              "null"
            ]
          },
          "paymentIban": {
            "type": [
              "string",
              "null"
            ]
          },
          "showSlaupyMark": {
            "type": "boolean"
          },
          "accent": {
            "$ref": "#/components/schemas/DocumentAccent"
          },
          "version": {
            "type": "integer",
            "description": "0 mientras no se ha guardado"
          }
        },
        "required": [
          "id",
          "seriesId",
          "layout",
          "accentColor",
          "font",
          "footerText",
          "paymentText",
          "paymentIban",
          "showSlaupyMark",
          "accent",
          "version"
        ]
      },
      "DocumentAccent": {
        "type": [
          "object",
          "null"
        ],
        "properties": {
          "color": {
            "type": "string",
            "description": "Color que se usa en el papel"
          },
          "adjusted": {
            "type": "boolean",
            "description": "Se ha oscurecido para llegar a AA sobre blanco"
          },
          "contrast": {
            "type": "number"
          }
        },
        "required": [
          "color",
          "adjusted",
          "contrast"
        ]
      },
      "DocumentLogo": {
        "type": [
          "object",
          "null"
        ],
        "properties": {
          "fileId": {
            "type": "string",
            "format": "uuid"
          },
          "width": {
            "type": "integer"
          },
          "height": {
            "type": "integer"
          }
        },
        "required": [
          "fileId",
          "width",
          "height"
        ]
      },
      "RecurringInvoice": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "contactId": {
            "type": "string",
            "format": "uuid"
          },
          "customerName": {
            "type": [
              "string",
              "null"
            ]
          },
          "customerTaxId": {
            "type": [
              "string",
              "null"
            ]
          },
          "estimate": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "subtotalMinor": {
                "type": "integer"
              },
              "taxMinor": {
                "type": "integer"
              },
              "withholdingMinor": {
                "type": "integer"
              },
              "totalMinor": {
                "type": "integer"
              }
            },
            "required": [
              "subtotalMinor",
              "taxMinor",
              "withholdingMinor",
              "totalMinor"
            ]
          },
          "seriesId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "frequency": {
            "type": "string",
            "enum": [
              "weekly",
              "monthly",
              "quarterly",
              "yearly"
            ]
          },
          "dayOfMonth": {
            "type": [
              "integer",
              "null"
            ]
          },
          "nextDate": {
            "type": "string"
          },
          "endDate": {
            "type": [
              "string",
              "null"
            ]
          },
          "mode": {
            "type": "string",
            "enum": [
              "draft",
              "issue"
            ]
          },
          "sendEmail": {
            "type": "boolean"
          },
          "autoIssueConfirmedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "active": {
            "type": "boolean"
          },
          "paymentMethod": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "transfer",
              "card",
              "cash",
              "direct_debit",
              "bizum",
              "other",
              null
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "deliveryCountry": {
            "type": [
              "string",
              "null"
            ],
            "description": "País de entrega de los bienes (ISO 3166-1, o ES-CN, ES-CE, ES-ML); null es el país del cliente. Pasa a cada factura"
          },
          "lines": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "productId": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "description": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "maxLength": 1000,
                  "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
                },
                "quantity": {
                  "type": "string"
                },
                "unitPrice": {
                  "type": "string"
                },
                "discountPct": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "taxCode": {
                  "type": "string"
                },
                "exemptionCause": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "enum": [
                    "E1",
                    "E2",
                    "E3",
                    "E4",
                    "E5",
                    "E6",
                    null
                  ]
                },
                "withholdingRate": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "unit": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "maxLength": 20,
                  "pattern": "^[^\\p{Cc}]*$/u"
                }
              },
              "required": [
                "quantity",
                "unitPrice",
                "taxCode"
              ],
              "additionalProperties": false
            }
          },
          "lastRunOn": {
            "type": [
              "string",
              "null"
            ]
          },
          "runs": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "runDate": {
                  "type": "string"
                },
                "result": {
                  "type": "string"
                },
                "invoiceId": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid"
                },
                "error": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "runDate",
                "result",
                "invoiceId",
                "error"
              ]
            }
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "name",
          "contactId",
          "customerName",
          "customerTaxId",
          "estimate",
          "seriesId",
          "frequency",
          "dayOfMonth",
          "nextDate",
          "endDate",
          "mode",
          "sendEmail",
          "autoIssueConfirmedAt",
          "active",
          "paymentMethod",
          "notes",
          "deliveryCountry",
          "lines",
          "lastRunOn",
          "runs",
          "version"
        ]
      },
      "QuotePage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Quote"
            }
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "items",
          "nextCursor"
        ]
      },
      "Quote": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "quote",
              "proforma"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "sent",
              "accepted",
              "rejected",
              "invoiced"
            ]
          },
          "fullNumber": {
            "type": "string"
          },
          "issueDate": {
            "type": "string"
          },
          "validUntil": {
            "type": [
              "string",
              "null"
            ]
          },
          "contactId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "customerName": {
            "type": [
              "string",
              "null"
            ]
          },
          "customerTaxId": {
            "type": [
              "string",
              "null"
            ]
          },
          "currency": {
            "type": "string"
          },
          "subtotalMinor": {
            "type": "integer"
          },
          "taxMinor": {
            "type": "integer"
          },
          "surchargeMinor": {
            "type": "integer"
          },
          "withholdingMinor": {
            "type": "integer"
          },
          "totalMinor": {
            "type": "integer"
          },
          "payableMinor": {
            "type": "integer"
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "documentLocale": {
            "type": "string",
            "enum": [
              "es",
              "en"
            ]
          },
          "deliveryCountry": {
            "type": [
              "string",
              "null"
            ],
            "description": "País de entrega de los bienes; null es el país del cliente. Pasa a la factura"
          },
          "sentAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "decidedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "decidedByName": {
            "type": [
              "string",
              "null"
            ]
          },
          "decidedVia": {
            "type": [
              "string",
              "null"
            ]
          },
          "publicLinkExpiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "invoiceId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "invoiceNumber": {
            "type": [
              "string",
              "null"
            ]
          },
          "version": {
            "type": "integer"
          },
          "lines": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/QuoteLine"
            }
          }
        },
        "required": [
          "id",
          "kind",
          "status",
          "fullNumber",
          "issueDate",
          "validUntil",
          "contactId",
          "customerName",
          "customerTaxId",
          "currency",
          "subtotalMinor",
          "taxMinor",
          "surchargeMinor",
          "withholdingMinor",
          "totalMinor",
          "payableMinor",
          "notes",
          "documentLocale",
          "deliveryCountry",
          "sentAt",
          "decidedAt",
          "decidedByName",
          "decidedVia",
          "publicLinkExpiresAt",
          "invoiceId",
          "invoiceNumber",
          "version",
          "lines"
        ]
      },
      "QuoteLine": {
        "type": "object",
        "properties": {
          "position": {
            "type": "integer"
          },
          "productId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "quantity": {
            "type": "string"
          },
          "unitPrice": {
            "type": "string"
          },
          "discountPct": {
            "type": [
              "string",
              "null"
            ]
          },
          "unit": {
            "type": [
              "string",
              "null"
            ]
          },
          "baseMinor": {
            "type": "integer"
          },
          "taxCode": {
            "type": "string"
          },
          "exemptionCause": {
            "type": [
              "string",
              "null"
            ]
          },
          "withholdingRate": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "position",
          "productId",
          "description",
          "quantity",
          "unitPrice",
          "discountPct",
          "unit",
          "baseMinor",
          "taxCode",
          "exemptionCause",
          "withholdingRate"
        ]
      },
      "InvoiceSent": {
        "type": "object",
        "properties": {
          "delivery": {
            "$ref": "#/components/schemas/InvoiceDelivery"
          },
          "publicUrl": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "sentAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "delivery",
          "publicUrl",
          "sentAt"
        ]
      },
      "InvoiceDelivery": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "to": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "cc": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "subject": {
            "type": "string"
          },
          "publicLinkExpiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "publicDownloads": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "to",
          "cc",
          "subject",
          "publicLinkExpiresAt",
          "publicDownloads",
          "createdAt"
        ]
      },
      "SendInvoice": {
        "type": "object",
        "properties": {
          "to": {
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 254,
              "format": "email"
            },
            "minItems": 1,
            "maxItems": 5
          },
          "cc": {
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 254,
              "format": "email"
            },
            "maxItems": 5,
            "default": []
          },
          "subject": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200,
            "pattern": "^[^\\p{Cc}]*$/u"
          },
          "message": {
            "type": "string",
            "maxLength": 4000,
            "pattern": "^(?:[^\\p{Cc}]|[\\n\\r\\t])*$/u"
          },
          "publicLink": {
            "type": "boolean",
            "default": false
          },
          "linkDays": {
            "type": "integer",
            "minimum": 1,
            "maximum": 90,
            "default": 30
          }
        },
        "required": [
          "to"
        ],
        "additionalProperties": false
      },
      "ExpenseCategory": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "description": "Código de sistema o `c:<id>` para las propias"
          },
          "id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "nameEn": {
            "type": [
              "string",
              "null"
            ]
          },
          "system": {
            "type": "boolean"
          },
          "parentCode": {
            "type": [
              "string",
              "null"
            ]
          },
          "concept": {
            "type": "string",
            "enum": [
              "consumos",
              "sueldos",
              "seguridad_social",
              "arrendamientos",
              "reparaciones",
              "servicios_profesionales",
              "suministros",
              "otros_servicios_exteriores",
              "tributos",
              "gastos_financieros",
              "amortizaciones",
              "otros"
            ]
          },
          "pgc": {
            "type": "string"
          },
          "vatDeductiblePct": {
            "type": "string"
          },
          "irpfDeductiblePct": {
            "type": "string"
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string"
                },
                "es": {
                  "type": "string"
                },
                "en": {
                  "type": "string"
                }
              },
              "required": [
                "code",
                "es",
                "en"
              ]
            }
          },
          "archivedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "code",
          "id",
          "name",
          "nameEn",
          "system",
          "parentCode",
          "concept",
          "pgc",
          "vatDeductiblePct",
          "irpfDeductiblePct",
          "warnings",
          "archivedAt",
          "version"
        ]
      },
      "Payables": {
        "type": "object",
        "properties": {
          "asOf": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "totalMinor": {
            "type": "integer"
          },
          "groups": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "group": {
                  "type": "string",
                  "enum": [
                    "overdue",
                    "this_week",
                    "this_month",
                    "later"
                  ]
                },
                "totalMinor": {
                  "type": "integer"
                },
                "items": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "number": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "supplierName": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "contactId": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "format": "uuid"
                      },
                      "issueDate": {
                        "type": "string"
                      },
                      "dueDate": {
                        "type": "string"
                      },
                      "dueSource": {
                        "type": "string",
                        "enum": [
                          "document",
                          "supplier",
                          "default"
                        ]
                      },
                      "outstandingMinor": {
                        "type": "integer"
                      },
                      "iban": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "ibanPending": {
                        "type": "boolean"
                      }
                    },
                    "required": [
                      "id",
                      "number",
                      "supplierName",
                      "contactId",
                      "issueDate",
                      "dueDate",
                      "dueSource",
                      "outstandingMinor",
                      "iban",
                      "ibanPending"
                    ]
                  }
                }
              },
              "required": [
                "group",
                "totalMinor",
                "items"
              ]
            }
          }
        },
        "required": [
          "asOf",
          "currency",
          "totalMinor",
          "groups"
        ]
      },
      "PurchaseTotals": {
        "type": "object",
        "properties": {
          "baseMinor": {
            "type": "integer"
          },
          "taxMinor": {
            "type": "integer"
          },
          "surchargeMinor": {
            "type": "integer"
          },
          "selfAssessedTaxMinor": {
            "type": "integer"
          },
          "deductibleTaxMinor": {
            "type": "integer"
          },
          "nonDeductibleTaxMinor": {
            "type": "integer"
          },
          "expenseMinor": {
            "type": "integer"
          },
          "irpfExpenseMinor": {
            "type": "integer"
          },
          "withholdingMinor": {
            "type": "integer"
          },
          "totalMinor": {
            "type": "integer"
          },
          "payableMinor": {
            "type": "integer"
          },
          "lines": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "taxMinor": {
                  "type": "integer"
                },
                "selfAssessedTaxMinor": {
                  "type": "integer"
                },
                "deductibleTaxMinor": {
                  "type": "integer"
                },
                "nonDeductibleTaxMinor": {
                  "type": "integer"
                },
                "irpfExpenseMinor": {
                  "type": "integer"
                },
                "problems": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "taxMinor",
                "selfAssessedTaxMinor",
                "deductibleTaxMinor",
                "nonDeductibleTaxMinor",
                "irpfExpenseMinor",
                "problems"
              ]
            }
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "baseMinor",
          "taxMinor",
          "surchargeMinor",
          "selfAssessedTaxMinor",
          "deductibleTaxMinor",
          "nonDeductibleTaxMinor",
          "expenseMinor",
          "irpfExpenseMinor",
          "withholdingMinor",
          "totalMinor",
          "payableMinor",
          "lines",
          "errors"
        ]
      },
      "SupplierDefaults": {
        "type": "object",
        "properties": {
          "found": {
            "type": "boolean"
          },
          "basis": {
            "type": "integer"
          },
          "operationKind": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "domestic",
              "intra_goods",
              "intra_services",
              "import",
              "reverse_charge_domestic",
              "not_subject",
              null
            ]
          },
          "documentKind": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "invoice",
              "simplified",
              "other",
              null
            ]
          },
          "categoryCode": {
            "type": [
              "string",
              "null"
            ]
          },
          "vatDeductiblePct": {
            "type": [
              "string",
              "null"
            ]
          },
          "irpfDeductiblePct": {
            "type": [
              "string",
              "null"
            ]
          },
          "withholdingKind": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "professional",
              "rental",
              null
            ]
          },
          "withholdingRate": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "found",
          "basis",
          "operationKind",
          "documentKind",
          "categoryCode",
          "vatDeductiblePct",
          "irpfDeductiblePct",
          "withholdingKind",
          "withholdingRate"
        ]
      },
      "PurchasePage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Purchase"
            }
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "items",
          "nextCursor"
        ]
      },
      "Purchase": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "confirmed"
            ]
          },
          "documentKind": {
            "type": "string",
            "enum": [
              "invoice",
              "simplified",
              "other"
            ]
          },
          "operationKind": {
            "type": "string",
            "enum": [
              "domestic",
              "intra_goods",
              "intra_services",
              "import",
              "reverse_charge_domestic",
              "not_subject"
            ]
          },
          "contactId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "supplierName": {
            "type": [
              "string",
              "null"
            ]
          },
          "supplierTaxId": {
            "type": [
              "string",
              "null"
            ]
          },
          "number": {
            "type": [
              "string",
              "null"
            ]
          },
          "issueDate": {
            "type": "string"
          },
          "operationDate": {
            "type": [
              "string",
              "null"
            ]
          },
          "registrationDate": {
            "type": "string"
          },
          "dueDate": {
            "type": [
              "string",
              "null"
            ]
          },
          "qualifiedSimplified": {
            "type": "boolean"
          },
          "supplierCashAccounting": {
            "type": "boolean"
          },
          "withholdingKind": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "professional",
              "rental",
              null
            ]
          },
          "withholdingRate": {
            "type": [
              "string",
              "null"
            ]
          },
          "baseMinor": {
            "type": "integer"
          },
          "taxMinor": {
            "type": "integer"
          },
          "surchargeMinor": {
            "type": "integer"
          },
          "selfAssessedTaxMinor": {
            "type": "integer"
          },
          "deductibleTaxMinor": {
            "type": "integer"
          },
          "nonDeductibleTaxMinor": {
            "type": "integer"
          },
          "expenseMinor": {
            "type": "integer"
          },
          "irpfExpenseMinor": {
            "type": "integer"
          },
          "withholdingMinor": {
            "type": "integer"
          },
          "totalMinor": {
            "type": "integer"
          },
          "payableMinor": {
            "type": "integer"
          },
          "paidMinor": {
            "type": "integer"
          },
          "paymentStatus": {
            "type": "string",
            "enum": [
              "unpaid",
              "partial",
              "paid"
            ]
          },
          "paymentMethod": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "transfer",
              "card",
              "cash",
              "direct_debit",
              "bizum",
              "other",
              null
            ]
          },
          "attachmentFileId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "source": {
            "type": "string",
            "enum": [
              "manual",
              "ai"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "periodClosed": {
            "type": "boolean"
          },
          "lines": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PurchaseLine"
            }
          },
          "version": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "status",
          "documentKind",
          "operationKind",
          "contactId",
          "supplierName",
          "supplierTaxId",
          "number",
          "issueDate",
          "operationDate",
          "registrationDate",
          "dueDate",
          "qualifiedSimplified",
          "supplierCashAccounting",
          "withholdingKind",
          "withholdingRate",
          "baseMinor",
          "taxMinor",
          "surchargeMinor",
          "selfAssessedTaxMinor",
          "deductibleTaxMinor",
          "nonDeductibleTaxMinor",
          "expenseMinor",
          "irpfExpenseMinor",
          "withholdingMinor",
          "totalMinor",
          "payableMinor",
          "paidMinor",
          "paymentStatus",
          "paymentMethod",
          "attachmentFileId",
          "source",
          "notes",
          "periodClosed",
          "lines",
          "version",
          "createdAt",
          "updatedAt"
        ]
      },
      "PurchaseLine": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "position": {
            "type": "integer"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "categoryCode": {
            "type": "string"
          },
          "baseMinor": {
            "type": "integer"
          },
          "taxRate": {
            "type": "string"
          },
          "surchargeRate": {
            "type": [
              "string",
              "null"
            ]
          },
          "vatDeductiblePct": {
            "type": "string"
          },
          "irpfDeductiblePct": {
            "type": "string"
          },
          "selfAssessmentRate": {
            "type": [
              "string",
              "null"
            ]
          },
          "taxMinor": {
            "type": "integer"
          },
          "surchargeMinor": {
            "type": "integer"
          },
          "selfAssessedTaxMinor": {
            "type": "integer"
          },
          "deductibleTaxMinor": {
            "type": "integer"
          },
          "nonDeductibleTaxMinor": {
            "type": "integer"
          },
          "expenseMinor": {
            "type": "integer"
          },
          "irpfExpenseMinor": {
            "type": "integer"
          },
          "isInvestment": {
            "type": "boolean"
          },
          "assetGroup": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "position",
          "description",
          "categoryCode",
          "baseMinor",
          "taxRate",
          "surchargeRate",
          "vatDeductiblePct",
          "irpfDeductiblePct",
          "selfAssessmentRate",
          "taxMinor",
          "surchargeMinor",
          "selfAssessedTaxMinor",
          "deductibleTaxMinor",
          "nonDeductibleTaxMinor",
          "expenseMinor",
          "irpfExpenseMinor",
          "isInvestment",
          "assetGroup"
        ]
      },
      "PurchasePayments": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PurchasePayment"
            }
          },
          "paidMinor": {
            "type": "integer"
          },
          "pendingMinor": {
            "type": "integer"
          },
          "paymentStatus": {
            "type": "string",
            "enum": [
              "unpaid",
              "partial",
              "paid"
            ]
          },
          "purchaseVersion": {
            "type": "integer"
          }
        },
        "required": [
          "items",
          "paidMinor",
          "pendingMinor",
          "paymentStatus",
          "purchaseVersion"
        ]
      },
      "PurchasePayment": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "paidOn": {
            "type": "string"
          },
          "amountMinor": {
            "type": "integer"
          },
          "method": {
            "type": "string",
            "enum": [
              "transfer",
              "card",
              "cash",
              "direct_debit",
              "bizum",
              "other"
            ]
          },
          "reference": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "paidOn",
          "amountMinor",
          "method",
          "reference",
          "createdAt"
        ]
      },
      "PaymentBatch": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "approved",
              "exported",
              "paid",
              "cancelled"
            ]
          },
          "debtorName": {
            "type": "string"
          },
          "debtorIban": {
            "type": "string"
          },
          "executionDate": {
            "type": "string"
          },
          "totalMinor": {
            "type": "integer"
          },
          "approvedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "createdBy": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "updatedBy": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "selfApproved": {
            "type": "boolean"
          },
          "exportedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "paidOn": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "version": {
            "type": "integer"
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "purchaseId": {
                  "type": "string",
                  "format": "uuid"
                },
                "creditorName": {
                  "type": "string"
                },
                "creditorIban": {
                  "type": "string"
                },
                "amountMinor": {
                  "type": "integer"
                },
                "remittance": {
                  "type": "string"
                },
                "paid": {
                  "type": "boolean"
                }
              },
              "required": [
                "purchaseId",
                "creditorName",
                "creditorIban",
                "amountMinor",
                "remittance",
                "paid"
              ]
            }
          }
        },
        "required": [
          "id",
          "status",
          "debtorName",
          "debtorIban",
          "executionDate",
          "totalMinor",
          "approvedAt",
          "createdBy",
          "updatedBy",
          "selfApproved",
          "exportedAt",
          "paidOn",
          "createdAt",
          "version",
          "items"
        ]
      },
      "InboxItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "fileId": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "reading",
              "read",
              "failed",
              "converted",
              "discarded"
            ]
          },
          "source": {
            "type": "string",
            "enum": [
              "web",
              "mobile",
              "email",
              "einvoice"
            ]
          },
          "originalName": {
            "type": "string"
          },
          "mime": {
            "type": "string"
          },
          "purchaseDocumentId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "emailId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "emailFrom": {
            "type": [
              "string",
              "null"
            ]
          },
          "senderUnverified": {
            "type": "boolean"
          },
          "version": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "fileId",
          "status",
          "source",
          "originalName",
          "mime",
          "purchaseDocumentId",
          "emailId",
          "emailFrom",
          "senderUnverified",
          "version",
          "createdAt"
        ]
      },
      "Asset": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "depreciationTable": {
            "type": "string",
            "enum": [
              "simplified",
              "corporate"
            ]
          },
          "groupCode": {
            "type": "string"
          },
          "groupName": {
            "type": "string"
          },
          "costMinor": {
            "type": "integer"
          },
          "businessUsePct": {
            "type": "string"
          },
          "depreciableMinor": {
            "type": "integer"
          },
          "startDate": {
            "type": "string"
          },
          "coefficientPct": {
            "type": "string"
          },
          "used": {
            "type": "boolean"
          },
          "freeDepreciation": {
            "type": "boolean"
          },
          "purchaseDocumentId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "disposed"
            ]
          },
          "disposedOn": {
            "type": [
              "string",
              "null"
            ]
          },
          "disposalPriceMinor": {
            "type": [
              "integer",
              "null"
            ]
          },
          "disposalResultMinor": {
            "type": [
              "integer",
              "null"
            ]
          },
          "accumulatedMinor": {
            "type": "integer"
          },
          "pendingMinor": {
            "type": "integer"
          },
          "schedule": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "year": {
                  "type": "integer"
                },
                "days": {
                  "type": "integer"
                },
                "amountMinor": {
                  "type": "integer"
                },
                "accumulatedMinor": {
                  "type": "integer"
                },
                "pendingMinor": {
                  "type": "integer"
                },
                "previous": {
                  "type": "boolean"
                }
              },
              "required": [
                "year",
                "days",
                "amountMinor",
                "accumulatedMinor",
                "pendingMinor",
                "previous"
              ]
            }
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "name",
          "depreciationTable",
          "groupCode",
          "groupName",
          "costMinor",
          "businessUsePct",
          "depreciableMinor",
          "startDate",
          "coefficientPct",
          "used",
          "freeDepreciation",
          "purchaseDocumentId",
          "status",
          "disposedOn",
          "disposalPriceMinor",
          "disposalResultMinor",
          "accumulatedMinor",
          "pendingMinor",
          "schedule",
          "version"
        ]
      },
      "AiStatus": {
        "type": "object",
        "properties": {
          "available": {
            "type": "boolean",
            "description": "Hay proveedor de IA configurado"
          },
          "enabled": {
            "type": "boolean",
            "description": "La organización la tiene activada"
          },
          "month": {
            "type": "string"
          },
          "trial": {
            "type": "boolean",
            "description": "En periodo de prueba: el cupo es para toda la prueba, no para el mes"
          },
          "quota": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Lecturas del mes; null en los planes sin límite con uso razonable"
          },
          "fairUse": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "normal",
              "warning",
              "saving",
              "paused",
              null
            ],
            "description": "Planes sin límite: aviso al acercarse al uso razonable, modo ahorro (solo el modelo rápido y menos lecturas por hora) o pausa hasta el mes siguiente"
          },
          "saving": {
            "type": "boolean",
            "description": "Gasto del mes por encima del tope de ahorro: solo el modelo rápido y menos lecturas por hora"
          },
          "bonus": {
            "type": "integer"
          },
          "used": {
            "type": "integer"
          },
          "remaining": {
            "type": [
              "integer",
              "null"
            ]
          },
          "warning": {
            "type": "boolean",
            "description": "Ha llegado al 80 % del cupo, o se acerca al uso razonable"
          },
          "blocked": {
            "type": "boolean",
            "description": "No lee con IA: cupo agotado, solo lectura o en pausa"
          },
          "paused": {
            "type": "boolean",
            "description": "En pausa hasta el mes siguiente: se ha llegado al tope mensual de gasto en IA y la organización no paga"
          },
          "hourlyLimit": {
            "type": "integer"
          },
          "bonusOffer": {
            "type": "object",
            "properties": {
              "readings": {
                "type": "integer"
              },
              "priceCents": {
                "type": "integer"
              }
            },
            "required": [
              "readings",
              "priceCents"
            ]
          }
        },
        "required": [
          "available",
          "enabled",
          "month",
          "trial",
          "quota",
          "fairUse",
          "saving",
          "bonus",
          "used",
          "remaining",
          "warning",
          "blocked",
          "paused",
          "hourlyLimit",
          "bonusOffer"
        ]
      },
      "AiReading": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "done",
              "cached",
              "failed",
              "skipped"
            ]
          },
          "skipReason": {
            "type": [
              "string",
              "null"
            ]
          },
          "models": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "retried": {
            "type": "boolean"
          },
          "retryReason": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "issues": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "review": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "purchaseDocumentId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "status",
          "skipReason",
          "models",
          "retried",
          "retryReason",
          "issues",
          "review",
          "purchaseDocumentId",
          "createdAt"
        ]
      },
      "TaxSettings": {
        "type": "object",
        "properties": {
          "year": {
            "type": "integer"
          },
          "vatRegime": {
            "type": "string",
            "enum": [
              "general",
              "equivalence_surcharge",
              "exempt",
              "small_business"
            ]
          },
          "cashAccounting": {
            "type": "boolean"
          },
          "irpfMethod": {
            "type": "string",
            "enum": [
              "simplified",
              "normal"
            ]
          },
          "activityKind": {
            "type": "string",
            "enum": [
              "professional",
              "business"
            ]
          },
          "retentionMajority": {
            "type": "boolean"
          },
          "prorataKind": {
            "type": "string",
            "enum": [
              "none",
              "general",
              "special"
            ]
          },
          "prorataProvisionalPct": {
            "type": [
              "string",
              "null"
            ]
          },
          "prorataFinalPct": {
            "type": [
              "string",
              "null"
            ]
          },
          "filingFrequency": {
            "type": "string",
            "enum": [
              "quarterly",
              "monthly"
            ]
          },
          "depreciationTable": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "simplified",
              "corporate",
              null
            ]
          },
          "activityStartDate": {
            "type": [
              "string",
              "null"
            ]
          },
          "newActivityReduction": {
            "type": "boolean"
          },
          "directDebit": {
            "type": "boolean"
          },
          "oneStopShop": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "lockedPeriods": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "year",
          "vatRegime",
          "cashAccounting",
          "irpfMethod",
          "activityKind",
          "retentionMajority",
          "prorataKind",
          "prorataProvisionalPct",
          "prorataFinalPct",
          "filingFrequency",
          "depreciationTable",
          "activityStartDate",
          "newActivityReduction",
          "directDebit",
          "oneStopShop",
          "lockedPeriods",
          "version"
        ]
      },
      "TaxReturn": {
        "type": "object",
        "properties": {
          "model": {
            "type": "string",
            "enum": [
              "111",
              "115",
              "130",
              "180",
              "190",
              "303",
              "347",
              "349",
              "390",
              "420",
              "425",
              "ipsi"
            ]
          },
          "year": {
            "type": "integer"
          },
          "period": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "calculated",
              "draft",
              "presented"
            ]
          },
          "boxes": {
            "type": "object",
            "additionalProperties": {
              "anyOf": [
                {
                  "type": "number"
                },
                {
                  "type": "string"
                },
                {
                  "type": "boolean"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "traces": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string"
                },
                "box": {
                  "type": "string"
                },
                "params": {
                  "type": "object",
                  "additionalProperties": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "number"
                      }
                    ]
                  }
                }
              },
              "required": [
                "code"
              ]
            }
          },
          "detail": {},
          "map": {
            "type": "object",
            "properties": {
              "title": {
                "type": "object",
                "properties": {
                  "es": {
                    "type": "string"
                  },
                  "en": {
                    "type": "string"
                  }
                },
                "required": [
                  "es",
                  "en"
                ]
              },
              "source": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "url": {
                    "type": "string"
                  }
                },
                "required": [
                  "title",
                  "url"
                ]
              },
              "sections": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "label": {
                      "type": "object",
                      "properties": {
                        "es": {
                          "type": "string"
                        },
                        "en": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "es",
                        "en"
                      ]
                    }
                  },
                  "required": [
                    "id",
                    "label"
                  ]
                }
              },
              "boxes": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "section": {
                      "type": "string"
                    },
                    "kind": {
                      "type": "string"
                    },
                    "label": {
                      "type": "object",
                      "properties": {
                        "es": {
                          "type": "string"
                        },
                        "en": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "es",
                        "en"
                      ]
                    },
                    "formula": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "id",
                    "section",
                    "kind",
                    "label"
                  ]
                }
              }
            },
            "required": [
              "title",
              "source",
              "sections",
              "boxes"
            ]
          },
          "draft": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "version": {
                "type": "integer"
              },
              "adjustments": {
                "type": "object",
                "additionalProperties": {
                  "type": "object",
                  "properties": {
                    "value": {
                      "type": "number"
                    },
                    "reason": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "value",
                    "reason"
                  ]
                }
              },
              "options": {
                "type": "object",
                "additionalProperties": {}
              },
              "rectifiesId": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uuid"
              }
            },
            "required": [
              "id",
              "version",
              "adjustments",
              "options",
              "rectifiesId"
            ]
          },
          "presented": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "receiptCode": {
                  "type": "string"
                },
                "presentedOn": {
                  "type": "string"
                },
                "declarationType": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "resultMinor": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "boxes": {
                  "type": "object",
                  "additionalProperties": {
                    "anyOf": [
                      {
                        "type": "number"
                      },
                      {
                        "type": "string"
                      },
                      {
                        "type": "boolean"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "engineVersion": {
                  "type": "string"
                },
                "rectifiesId": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid"
                },
                "outdated": {
                  "type": "boolean"
                }
              },
              "required": [
                "id",
                "receiptCode",
                "presentedOn",
                "declarationType",
                "resultMinor",
                "boxes",
                "engineVersion",
                "rectifiesId",
                "outdated"
              ]
            }
          },
          "difference": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "box": {
                  "type": "string"
                },
                "presented": {
                  "anyOf": [
                    {
                      "type": "number"
                    },
                    {
                      "type": "string"
                    },
                    {
                      "type": "boolean"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "live": {
                  "anyOf": [
                    {
                      "type": "number"
                    },
                    {
                      "type": "string"
                    },
                    {
                      "type": "boolean"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "box",
                "presented",
                "live"
              ]
            }
          },
          "facts": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "docKind": {
                  "type": "string"
                },
                "docId": {
                  "type": "string"
                },
                "number": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "date": {
                  "type": "string"
                },
                "counterparty": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "base": {
                  "type": "integer"
                },
                "tax": {
                  "type": "integer"
                },
                "amount": {
                  "type": "integer"
                }
              },
              "required": [
                "id",
                "docKind",
                "docId",
                "number",
                "date",
                "counterparty",
                "base",
                "tax",
                "amount"
              ]
            }
          },
          "suggestClose": {
            "type": "boolean"
          }
        },
        "required": [
          "model",
          "year",
          "period",
          "status",
          "boxes",
          "traces",
          "warnings",
          "map",
          "draft",
          "presented",
          "difference",
          "facts",
          "suggestClose"
        ]
      },
      "TaxPeriod": {
        "type": "object",
        "properties": {
          "period": {
            "type": "string"
          },
          "closed": {
            "type": "boolean"
          },
          "closedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "reopenedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "reason": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "period",
          "closed",
          "closedAt",
          "reopenedAt",
          "reason"
        ]
      },
      "Dashboard": {
        "type": "object",
        "properties": {
          "year": {
            "type": "integer"
          },
          "quarter": {
            "type": "string"
          },
          "vat": {
            "type": "object",
            "properties": {
              "model": {
                "type": "string",
                "enum": [
                  "303",
                  "420",
                  "ipsi"
                ]
              },
              "resultMinor": {
                "type": "integer"
              },
              "required": {
                "type": "boolean"
              },
              "outputMinor": {
                "type": "integer"
              },
              "inputMinor": {
                "type": "integer"
              }
            },
            "required": [
              "model",
              "resultMinor",
              "required",
              "outputMinor",
              "inputMinor"
            ]
          },
          "incomeTax": {
            "type": "object",
            "properties": {
              "model": {
                "type": "string",
                "enum": [
                  "130"
                ]
              },
              "resultMinor": {
                "type": "integer"
              },
              "required": {
                "type": "boolean"
              }
            },
            "required": [
              "model",
              "resultMinor",
              "required"
            ]
          },
          "receivable": {
            "type": "object",
            "properties": {
              "pendingMinor": {
                "type": "integer"
              },
              "overdueMinor": {
                "type": "integer"
              },
              "overdueCount": {
                "type": "integer"
              }
            },
            "required": [
              "pendingMinor",
              "overdueMinor",
              "overdueCount"
            ]
          },
          "yearToDate": {
            "type": "object",
            "properties": {
              "incomeMinor": {
                "type": "integer"
              },
              "expensesMinor": {
                "type": "integer"
              },
              "netMinor": {
                "type": "integer"
              },
              "withholdingsMinor": {
                "type": "integer"
              }
            },
            "required": [
              "incomeMinor",
              "expensesMinor",
              "netMinor",
              "withholdingsMinor"
            ]
          },
          "quarterToDate": {
            "type": "object",
            "properties": {
              "incomeMinor": {
                "type": "integer"
              },
              "expensesMinor": {
                "type": "integer"
              },
              "netMinor": {
                "type": "integer"
              },
              "withholdingsMinor": {
                "type": "integer"
              }
            },
            "required": [
              "incomeMinor",
              "expensesMinor",
              "netMinor",
              "withholdingsMinor"
            ]
          },
          "months": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "month": {
                  "type": "string"
                },
                "incomeMinor": {
                  "type": "integer"
                },
                "expensesMinor": {
                  "type": "integer"
                }
              },
              "required": [
                "month",
                "incomeMinor",
                "expensesMinor"
              ]
            }
          },
          "deadlines": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "model": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "period": {
                  "type": "string"
                },
                "year": {
                  "type": "integer"
                },
                "end": {
                  "type": "string"
                }
              },
              "required": [
                "model",
                "name",
                "period",
                "year",
                "end"
              ]
            }
          }
        },
        "required": [
          "year",
          "quarter",
          "vat",
          "incomeTax",
          "receivable",
          "yearToDate",
          "quarterToDate",
          "months",
          "deadlines"
        ]
      },
      "TaxCalendar": {
        "type": "object",
        "properties": {
          "year": {
            "type": "integer"
          },
          "models": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "deadlines": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "model": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "year": {
                  "type": "integer"
                },
                "period": {
                  "type": "string"
                },
                "start": {
                  "type": "string"
                },
                "end": {
                  "type": "string"
                },
                "directDebitEnd": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "moved": {
                  "type": "boolean"
                }
              },
              "required": [
                "model",
                "name",
                "year",
                "period",
                "start",
                "end",
                "directDebitEnd",
                "moved"
              ]
            }
          },
          "feed": {
            "$ref": "#/components/schemas/TaxCalendarFeed"
          }
        },
        "required": [
          "year",
          "models",
          "deadlines",
          "feed"
        ]
      },
      "TaxCalendarFeed": {
        "type": [
          "object",
          "null"
        ],
        "properties": {
          "rotatedAt": {
            "type": "string"
          }
        },
        "required": [
          "rotatedAt"
        ]
      },
      "TaxCalendarFeedCreated": {
        "type": "object",
        "properties": {
          "path": {
            "type": "string"
          },
          "rotatedAt": {
            "type": "string"
          }
        },
        "required": [
          "path",
          "rotatedAt"
        ]
      },
      "AnnualIncome": {
        "type": "object",
        "properties": {
          "year": {
            "type": "integer"
          },
          "mapYear": {
            "type": "integer"
          },
          "method": {
            "type": "string",
            "enum": [
              "simplified",
              "normal"
            ]
          },
          "boxes": {
            "type": "object",
            "additionalProperties": {
              "type": "number"
            }
          },
          "traces": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string"
                },
                "box": {
                  "type": "string"
                },
                "params": {
                  "type": "object",
                  "additionalProperties": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "number"
                      }
                    ]
                  }
                }
              },
              "required": [
                "code"
              ]
            }
          },
          "map": {
            "type": "object",
            "properties": {
              "title": {
                "type": "object",
                "properties": {
                  "es": {
                    "type": "string"
                  },
                  "en": {
                    "type": "string"
                  }
                },
                "required": [
                  "es",
                  "en"
                ]
              },
              "source": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "url": {
                    "type": "string"
                  }
                },
                "required": [
                  "title",
                  "url"
                ]
              },
              "sections": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "label": {
                      "type": "object",
                      "properties": {
                        "es": {
                          "type": "string"
                        },
                        "en": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "es",
                        "en"
                      ]
                    }
                  },
                  "required": [
                    "id",
                    "label"
                  ]
                }
              },
              "boxes": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "section": {
                      "type": "string"
                    },
                    "label": {
                      "type": "object",
                      "properties": {
                        "es": {
                          "type": "string"
                        },
                        "en": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "es",
                        "en"
                      ]
                    },
                    "formula": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "id",
                    "section",
                    "label"
                  ]
                }
              }
            },
            "required": [
              "title",
              "source",
              "sections",
              "boxes"
            ]
          },
          "withholdings": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "taxId": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "name": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "baseMinor": {
                  "type": "integer"
                },
                "amountMinor": {
                  "type": "integer"
                },
                "certificate": {
                  "type": [
                    "object",
                    "null"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "fileId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "id",
                    "fileId",
                    "name"
                  ]
                }
              },
              "required": [
                "taxId",
                "name",
                "baseMinor",
                "amountMinor",
                "certificate"
              ]
            }
          },
          "instalments": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "period": {
                  "type": "string"
                },
                "amountMinor": {
                  "type": "integer"
                },
                "presentedOn": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "period",
                "amountMinor",
                "presentedOn"
              ]
            }
          },
          "notComputed": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "checklist": {
            "type": "object",
            "properties": {
              "openPeriods": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "unfiledReturns": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "model": {
                      "type": "string"
                    },
                    "period": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "model",
                    "period"
                  ]
                }
              },
              "missingCertificates": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "taxId": {
                      "type": "string"
                    },
                    "name": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "amountMinor": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "taxId",
                    "name",
                    "amountMinor"
                  ]
                }
              },
              "expensesWithoutReceipt": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "number": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "supplier": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "date": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "id",
                    "number",
                    "supplier",
                    "date"
                  ]
                }
              },
              "investmentsWithoutAsset": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "number": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "supplier": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "date": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "id",
                    "number",
                    "supplier",
                    "date"
                  ]
                }
              },
              "q4": {
                "type": "object",
                "properties": {
                  "filed": {
                    "type": "boolean"
                  },
                  "netMinor": {
                    "type": "integer"
                  },
                  "annualNetMinor": {
                    "type": "integer"
                  },
                  "differenceMinor": {
                    "type": "integer"
                  },
                  "reasons": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "required": [
                  "filed",
                  "netMinor",
                  "annualNetMinor",
                  "differenceMinor",
                  "reasons"
                ]
              }
            },
            "required": [
              "openPeriods",
              "unfiledReturns",
              "missingCertificates",
              "expensesWithoutReceipt",
              "investmentsWithoutAsset",
              "q4"
            ]
          },
          "facts": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "docKind": {
                  "type": "string"
                },
                "docId": {
                  "type": "string"
                },
                "number": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "date": {
                  "type": "string"
                },
                "counterparty": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "amount": {
                  "type": "integer"
                }
              },
              "required": [
                "id",
                "docKind",
                "docId",
                "number",
                "date",
                "counterparty",
                "amount"
              ]
            }
          }
        },
        "required": [
          "year",
          "mapYear",
          "method",
          "boxes",
          "traces",
          "warnings",
          "map",
          "withholdings",
          "instalments",
          "notComputed",
          "checklist",
          "facts"
        ]
      },
      "Dac7Reconciliation": {
        "type": "object",
        "properties": {
          "year": {
            "type": "integer"
          },
          "years": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "alerts": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "channel": {
                  "type": "string"
                },
                "year": {
                  "type": "integer"
                },
                "quarter": {
                  "type": "integer"
                },
                "differenceMinor": {
                  "type": "integer"
                }
              },
              "required": [
                "channel",
                "year",
                "quarter",
                "differenceMinor"
              ]
            }
          },
          "channels": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "name": {
                  "type": "string"
                },
                "kind": {
                  "type": "string",
                  "enum": [
                    "shopify",
                    "amazon",
                    "stripe",
                    "other"
                  ]
                },
                "quarters": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "quarter": {
                        "type": "integer"
                      },
                      "statement": {
                        "type": [
                          "object",
                          "null"
                        ],
                        "properties": {
                          "grossMinor": {
                            "type": "integer"
                          },
                          "operations": {
                            "type": "integer"
                          },
                          "feesMinor": {
                            "type": "integer"
                          },
                          "fileId": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "uuid"
                          },
                          "version": {
                            "type": "integer"
                          }
                        },
                        "required": [
                          "grossMinor",
                          "operations",
                          "feesMinor",
                          "fileId",
                          "version"
                        ]
                      },
                      "recorded": {
                        "type": "object",
                        "properties": {
                          "salesMinor": {
                            "type": "integer"
                          },
                          "refundsMinor": {
                            "type": "integer"
                          },
                          "netMinor": {
                            "type": "integer"
                          },
                          "operations": {
                            "type": "integer"
                          },
                          "feesMinor": {
                            "type": "integer"
                          }
                        },
                        "required": [
                          "salesMinor",
                          "refundsMinor",
                          "netMinor",
                          "operations",
                          "feesMinor"
                        ]
                      },
                      "result": {
                        "type": "object",
                        "properties": {
                          "status": {
                            "type": "string",
                            "enum": [
                              "matches",
                              "differs",
                              "no_statement"
                            ]
                          },
                          "differenceMinor": {
                            "type": "integer"
                          },
                          "feesDifferenceMinor": {
                            "type": "integer"
                          },
                          "causes": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "cause": {
                                  "type": "string",
                                  "enum": [
                                    "refunds",
                                    "boundary",
                                    "other_channel",
                                    "unrecorded",
                                    "fees_unrecorded"
                                  ]
                                },
                                "amountMinor": {
                                  "type": "integer"
                                }
                              },
                              "required": [
                                "cause",
                                "amountMinor"
                              ]
                            }
                          }
                        },
                        "required": [
                          "status",
                          "differenceMinor",
                          "feesDifferenceMinor",
                          "causes"
                        ]
                      }
                    },
                    "required": [
                      "quarter",
                      "statement",
                      "recorded",
                      "result"
                    ]
                  }
                }
              },
              "required": [
                "id",
                "name",
                "kind",
                "quarters"
              ]
            }
          }
        },
        "required": [
          "year",
          "years",
          "alerts",
          "channels"
        ]
      },
      "DistanceSales": {
        "type": "object",
        "properties": {
          "year": {
            "type": "integer"
          },
          "thresholdMinor": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Umbral sin IVA; null antes de 2021-07-01"
          },
          "warningPct": {
            "type": "integer"
          },
          "previousYearMinor": {
            "type": "integer"
          },
          "currentYearMinor": {
            "type": "integer"
          },
          "level": {
            "type": "string",
            "enum": [
              "below",
              "near",
              "over"
            ]
          },
          "fromOtherState": {
            "type": "boolean",
            "description": "Alguna venta sale de un almacén de otro Estado miembro: el umbral no se aplica (art. 73.Uno, párrafo tercero)"
          },
          "crossedOn": {
            "type": [
              "string",
              "null"
            ]
          },
          "byCountry": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "country": {
                  "type": "string"
                },
                "baseMinor": {
                  "type": "integer"
                },
                "documents": {
                  "type": "integer"
                },
                "byRate": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "rate": {
                        "type": "string",
                        "description": "Tipo de IVA aplicado (%)"
                      },
                      "baseMinor": {
                        "type": "integer"
                      },
                      "documents": {
                        "type": "integer"
                      }
                    },
                    "required": [
                      "rate",
                      "baseMinor",
                      "documents"
                    ]
                  }
                }
              },
              "required": [
                "country",
                "baseMinor",
                "documents",
                "byRate"
              ]
            }
          },
          "taxedInSpainOver": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "invoiceId": {
                  "type": "string"
                },
                "number": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "date": {
                  "type": "string"
                },
                "country": {
                  "type": "string"
                },
                "baseMinor": {
                  "type": "integer"
                }
              },
              "required": [
                "invoiceId",
                "number",
                "date",
                "country",
                "baseMinor"
              ]
            },
            "description": "Facturas con IVA español después de superar el umbral"
          }
        },
        "required": [
          "year",
          "thresholdMinor",
          "warningPct",
          "previousYearMinor",
          "currentYearMinor",
          "level",
          "fromOtherState",
          "crossedOn",
          "byCountry",
          "taxedInSpainOver"
        ]
      },
      "PostingRules": {
        "type": "object",
        "properties": {
          "accounts": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "key": {
                  "type": "string",
                  "enum": [
                    "sales_goods",
                    "sales_services",
                    "output_vat",
                    "sales_withholding",
                    "customer_fallback",
                    "input_vat",
                    "purchase_withholding",
                    "supplier_fallback",
                    "creditor_fallback",
                    "bank",
                    "cash",
                    "vat_payable",
                    "vat_to_offset",
                    "vat_refund",
                    "depreciation_tangible",
                    "depreciation_intangible",
                    "disposal_loss",
                    "disposal_gain",
                    "payroll_wages",
                    "payroll_employer_ss",
                    "payroll_ss_payable",
                    "payroll_withholding",
                    "payroll_net_payable",
                    "expense_fallback"
                  ]
                },
                "defaultCode": {
                  "type": "string"
                },
                "code": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                }
              },
              "required": [
                "key",
                "defaultCode",
                "code",
                "name"
              ]
            }
          },
          "expenses": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "category": {
                  "type": "string"
                },
                "defaultCode": {
                  "type": "string"
                },
                "code": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                }
              },
              "required": [
                "category",
                "defaultCode",
                "code",
                "name"
              ]
            }
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "accounts",
          "expenses",
          "version"
        ]
      },
      "PendingPosting": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "sourceType": {
            "type": "string",
            "enum": [
              "invoice",
              "purchase_document",
              "invoice_payment",
              "purchase_payment",
              "asset_depreciation",
              "payroll",
              "tax_return"
            ]
          },
          "sourceId": {
            "type": "string"
          },
          "attempts": {
            "type": "integer"
          },
          "problem": {
            "type": [
              "string",
              "null"
            ]
          },
          "problemDetail": {
            "type": [
              "string",
              "null"
            ]
          },
          "since": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "sourceType",
          "sourceId",
          "attempts",
          "problem",
          "problemDetail",
          "since"
        ]
      },
      "AutomaticPostingRun": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "done",
              "failed"
            ]
          },
          "rebuild": {
            "type": "boolean"
          },
          "total": {
            "type": "integer"
          },
          "processed": {
            "type": "integer"
          },
          "posted": {
            "type": "integer"
          },
          "reversed": {
            "type": "integer"
          },
          "unchanged": {
            "type": "integer"
          },
          "failed": {
            "type": "integer"
          },
          "stalled": {
            "type": "boolean"
          },
          "createdAt": {
            "type": "string"
          },
          "startedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "finishedAt": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "status",
          "rebuild",
          "total",
          "processed",
          "posted",
          "reversed",
          "unchanged",
          "failed",
          "stalled",
          "createdAt",
          "startedAt",
          "finishedAt"
        ]
      },
      "AnnualAccounts": {
        "type": "object",
        "properties": {
          "fiscalYearId": {
            "type": "string"
          },
          "balance": {
            "type": "object",
            "properties": {
              "assets": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "key": {
                      "type": "string"
                    },
                    "label": {
                      "type": "string"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "lines": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "key": {
                            "type": "string"
                          },
                          "label": {
                            "type": "string"
                          },
                          "amount": {
                            "type": "integer"
                          }
                        },
                        "required": [
                          "key",
                          "label",
                          "amount"
                        ]
                      }
                    }
                  },
                  "required": [
                    "key",
                    "label",
                    "total",
                    "lines"
                  ]
                }
              },
              "equityAndLiabilities": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "key": {
                      "type": "string"
                    },
                    "label": {
                      "type": "string"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "lines": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "key": {
                            "type": "string"
                          },
                          "label": {
                            "type": "string"
                          },
                          "amount": {
                            "type": "integer"
                          }
                        },
                        "required": [
                          "key",
                          "label",
                          "amount"
                        ]
                      }
                    }
                  },
                  "required": [
                    "key",
                    "label",
                    "total",
                    "lines"
                  ]
                }
              },
              "totalAssets": {
                "type": "integer"
              },
              "totalEquityAndLiabilities": {
                "type": "integer"
              }
            },
            "required": [
              "assets",
              "equityAndLiabilities",
              "totalAssets",
              "totalEquityAndLiabilities"
            ]
          },
          "profitAndLoss": {
            "type": "object",
            "properties": {
              "lines": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "key": {
                      "type": "string"
                    },
                    "label": {
                      "type": "string"
                    },
                    "amount": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "key",
                    "label",
                    "amount"
                  ]
                }
              },
              "operatingResult": {
                "type": "integer"
              },
              "financialResult": {
                "type": "integer"
              },
              "resultBeforeTax": {
                "type": "integer"
              },
              "result": {
                "type": "integer"
              }
            },
            "required": [
              "lines",
              "operatingResult",
              "financialResult",
              "resultBeforeTax",
              "result"
            ]
          },
          "unclassified": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string"
                },
                "balance": {
                  "type": "integer"
                }
              },
              "required": [
                "code",
                "balance"
              ]
            }
          }
        },
        "required": [
          "fiscalYearId",
          "balance",
          "profitAndLoss",
          "unclassified"
        ]
      },
      "Ledger": {
        "type": "object",
        "properties": {
          "account": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "name"
            ]
          },
          "openingMinor": {
            "type": "integer"
          },
          "totals": {
            "type": "object",
            "properties": {
              "openingMinor": {
                "type": "integer"
              },
              "debitMinor": {
                "type": "integer"
              },
              "creditMinor": {
                "type": "integer"
              },
              "closingMinor": {
                "type": "integer"
              }
            },
            "required": [
              "openingMinor",
              "debitMinor",
              "creditMinor",
              "closingMinor"
            ]
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LedgerLine"
            }
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "account",
          "openingMinor",
          "totals",
          "items",
          "nextCursor"
        ]
      },
      "LedgerLine": {
        "type": "object",
        "properties": {
          "entryId": {
            "type": "string"
          },
          "number": {
            "type": "integer"
          },
          "date": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "lineNo": {
            "type": "integer"
          },
          "lineDescription": {
            "type": [
              "string",
              "null"
            ]
          },
          "accountCode": {
            "type": "string"
          },
          "accountName": {
            "type": "string"
          },
          "debitMinor": {
            "type": "integer"
          },
          "creditMinor": {
            "type": "integer"
          },
          "balanceMinor": {
            "type": "integer"
          }
        },
        "required": [
          "entryId",
          "number",
          "date",
          "description",
          "lineNo",
          "lineDescription",
          "accountCode",
          "accountName",
          "debitMinor",
          "creditMinor",
          "balanceMinor"
        ]
      },
      "TrialBalance": {
        "type": "object",
        "properties": {
          "level": {
            "type": "integer"
          },
          "totals": {
            "type": "object",
            "properties": {
              "openingMinor": {
                "type": "integer"
              },
              "debitMinor": {
                "type": "integer"
              },
              "creditMinor": {
                "type": "integer"
              },
              "closingMinor": {
                "type": "integer"
              }
            },
            "required": [
              "openingMinor",
              "debitMinor",
              "creditMinor",
              "closingMinor"
            ]
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TrialBalanceRow"
            }
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "level",
          "totals",
          "items",
          "nextCursor"
        ]
      },
      "TrialBalanceRow": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "openingMinor": {
            "type": "integer"
          },
          "debitMinor": {
            "type": "integer"
          },
          "creditMinor": {
            "type": "integer"
          },
          "closingMinor": {
            "type": "integer"
          }
        },
        "required": [
          "code",
          "name",
          "openingMinor",
          "debitMinor",
          "creditMinor",
          "closingMinor"
        ]
      },
      "AccountingExportSettings": {
        "type": "object",
        "properties": {
          "program": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "a3",
              "contasol",
              "sage",
              null
            ]
          },
          "companyCode": {
            "type": [
              "integer",
              "null"
            ]
          },
          "accountLength": {
            "type": [
              "integer",
              "null"
            ]
          }
        },
        "required": [
          "program",
          "companyCode",
          "accountLength"
        ]
      },
      "PayrollSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "period": {
            "type": "string"
          },
          "paidOn": {
            "type": "string"
          },
          "label": {
            "type": [
              "string",
              "null"
            ]
          },
          "employees": {
            "type": "integer"
          },
          "grossMinor": {
            "type": "integer"
          },
          "withheldMinor": {
            "type": "integer"
          },
          "inKindMinor": {
            "type": "integer"
          },
          "inKindWithheldMinor": {
            "type": "integer"
          },
          "employeeSsMinor": {
            "type": "integer"
          },
          "employerSsMinor": {
            "type": "integer"
          },
          "netMinor": {
            "type": "integer"
          },
          "lines": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PayrollLine"
            }
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "period",
          "paidOn",
          "label",
          "employees",
          "grossMinor",
          "withheldMinor",
          "inKindMinor",
          "inKindWithheldMinor",
          "employeeSsMinor",
          "employerSsMinor",
          "netMinor",
          "lines",
          "version"
        ]
      },
      "PayrollLine": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "employeeName": {
            "type": "string"
          },
          "employeeTaxId": {
            "type": "string"
          },
          "postalCode": {
            "type": [
              "string",
              "null"
            ]
          },
          "grossMinor": {
            "type": "integer"
          },
          "withheldMinor": {
            "type": "integer"
          },
          "inKindMinor": {
            "type": "integer"
          },
          "inKindWithheldMinor": {
            "type": "integer"
          },
          "employeeSsMinor": {
            "type": "integer"
          },
          "employerSsMinor": {
            "type": "integer"
          },
          "netMinor": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "employeeName",
          "employeeTaxId",
          "postalCode",
          "grossMinor",
          "withheldMinor",
          "inKindMinor",
          "inKindWithheldMinor",
          "employeeSsMinor",
          "employerSsMinor",
          "netMinor"
        ]
      },
      "ApprovalPolicy": {
        "type": "object",
        "properties": {
          "purchaseThresholdMinor": {
            "type": [
              "integer",
              "null"
            ]
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "purchaseThresholdMinor",
          "version"
        ]
      },
      "Approval": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "purchaseId": {
            "type": "string"
          },
          "supplierName": {
            "type": [
              "string",
              "null"
            ]
          },
          "number": {
            "type": [
              "string",
              "null"
            ]
          },
          "issueDate": {
            "type": "string"
          },
          "amountMinor": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "approved",
              "rejected"
            ]
          },
          "requestedBy": {
            "type": [
              "string",
              "null"
            ]
          },
          "decidedBy": {
            "type": [
              "string",
              "null"
            ]
          },
          "decidedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "note": {
            "type": [
              "string",
              "null"
            ]
          },
          "selfApproved": {
            "type": "boolean"
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "purchaseId",
          "supplierName",
          "number",
          "issueDate",
          "amountMinor",
          "status",
          "requestedBy",
          "decidedBy",
          "decidedAt",
          "note",
          "selfApproved",
          "version"
        ]
      },
      "Model200Draft": {
        "type": "object",
        "properties": {
          "accountingResultMinor": {
            "type": "integer"
          },
          "taxExpenseMinor": {
            "type": "integer"
          },
          "withholdingsMinor": {
            "type": "integer"
          },
          "preliminaryBaseMinor": {
            "type": "integer"
          },
          "offsetLossesMinor": {
            "type": "integer"
          },
          "baseMinor": {
            "type": "integer"
          },
          "bands": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "upToMinor": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "pct": {
                  "type": "number"
                }
              },
              "required": [
                "upToMinor",
                "pct"
              ]
            }
          },
          "grossQuotaMinor": {
            "type": "integer"
          },
          "netQuotaMinor": {
            "type": "integer"
          },
          "resultMinor": {
            "type": "integer"
          },
          "lossesCarriedMinor": {
            "type": "integer"
          }
        },
        "required": [
          "accountingResultMinor",
          "taxExpenseMinor",
          "withholdingsMinor",
          "preliminaryBaseMinor",
          "offsetLossesMinor",
          "baseMinor",
          "bands",
          "grossQuotaMinor",
          "netQuotaMinor",
          "resultMinor",
          "lossesCarriedMinor"
        ]
      },
      "Model202": {
        "type": "object",
        "properties": {
          "from": {
            "type": "string"
          },
          "to": {
            "type": "string"
          },
          "periodBaseMinor": {
            "type": "integer"
          },
          "withholdingsMinor": {
            "type": "integer"
          },
          "pct": {
            "type": "number"
          },
          "amountMinor": {
            "type": "integer"
          }
        },
        "required": [
          "from",
          "to",
          "periodBaseMinor",
          "withholdingsMinor",
          "pct",
          "amountMinor"
        ]
      },
      "AccountChart": {
        "type": [
          "object",
          "null"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "template": {
            "type": "string"
          },
          "templateVersion": {
            "type": "string"
          },
          "templateName": {
            "type": "string"
          },
          "source": {
            "type": "object",
            "properties": {
              "title": {
                "type": "string"
              },
              "boeId": {
                "type": "string"
              },
              "url": {
                "type": "string"
              },
              "notes": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "title",
              "boeId",
              "url",
              "notes"
            ]
          },
          "subaccountLength": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "template",
          "templateVersion",
          "templateName",
          "source",
          "subaccountLength",
          "createdAt"
        ]
      },
      "Account": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "parentCode": {
            "type": [
              "string",
              "null"
            ]
          },
          "postable": {
            "type": "boolean"
          },
          "contactId": {
            "type": [
              "string",
              "null"
            ]
          },
          "contactRole": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "customer",
              "supplier",
              "creditor",
              null
            ]
          },
          "archived": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "code",
          "name",
          "parentCode",
          "postable",
          "contactId",
          "contactRole",
          "archived"
        ]
      },
      "FiscalYear": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "startDate": {
            "type": "string"
          },
          "endDate": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "closed"
            ]
          },
          "closing": {
            "type": "boolean"
          },
          "lastEntryNumber": {
            "type": "integer"
          },
          "resultMinor": {
            "type": [
              "integer",
              "null"
            ]
          },
          "closedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "name",
          "startDate",
          "endDate",
          "status",
          "closing",
          "lastEntryNumber",
          "resultMinor",
          "closedAt",
          "version"
        ]
      },
      "FiscalYearClosing": {
        "type": "object",
        "properties": {
          "resultMinor": {
            "type": "integer"
          },
          "regularization": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "accountCode": {
                  "type": "string"
                },
                "debitMinor": {
                  "type": "integer"
                },
                "creditMinor": {
                  "type": "integer"
                }
              },
              "required": [
                "accountCode",
                "debitMinor",
                "creditMinor"
              ]
            }
          },
          "closing": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "accountCode": {
                  "type": "string"
                },
                "debitMinor": {
                  "type": "integer"
                },
                "creditMinor": {
                  "type": "integer"
                }
              },
              "required": [
                "accountCode",
                "debitMinor",
                "creditMinor"
              ]
            }
          },
          "opening": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "accountCode": {
                  "type": "string"
                },
                "debitMinor": {
                  "type": "integer"
                },
                "creditMinor": {
                  "type": "integer"
                }
              },
              "required": [
                "accountCode",
                "debitMinor",
                "creditMinor"
              ]
            }
          },
          "blockers": {
            "type": "object",
            "properties": {
              "draftEntries": {
                "type": "integer"
              },
              "earlierOpenYears": {
                "type": "integer"
              },
              "pendingDocuments": {
                "type": "integer"
              }
            },
            "required": [
              "draftEntries",
              "earlierOpenYears",
              "pendingDocuments"
            ]
          }
        },
        "required": [
          "resultMinor",
          "regularization",
          "closing",
          "opening",
          "blockers"
        ]
      },
      "FiscalYearRun": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "fiscalYearId": {
            "type": "string"
          },
          "action": {
            "type": "string",
            "enum": [
              "close",
              "reopen"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "done",
              "failed"
            ]
          },
          "phase": {
            "type": "string",
            "enum": [
              "posting",
              "finishing"
            ]
          },
          "total": {
            "type": "integer"
          },
          "processed": {
            "type": "integer"
          },
          "posted": {
            "type": "integer"
          },
          "failed": {
            "type": "integer"
          },
          "stalled": {
            "type": "boolean"
          },
          "error": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "detail": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "code",
              "detail"
            ]
          },
          "result": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "nextYearId": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "entryIds": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "resultMinor": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            },
            "required": [
              "nextYearId",
              "entryIds",
              "resultMinor"
            ]
          },
          "createdAt": {
            "type": "string"
          },
          "startedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "finishedAt": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "fiscalYearId",
          "action",
          "status",
          "phase",
          "total",
          "processed",
          "posted",
          "failed",
          "stalled",
          "error",
          "result",
          "createdAt",
          "startedAt",
          "finishedAt"
        ]
      },
      "JournalEntry": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "fiscalYearId": {
            "type": "string"
          },
          "number": {
            "type": [
              "integer",
              "null"
            ]
          },
          "date": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "manual",
              "automatic",
              "reversal",
              "regularization",
              "closing",
              "opening"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "posted"
            ]
          },
          "sourceType": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "invoice",
              "purchase_document",
              "invoice_payment",
              "purchase_payment",
              "asset_depreciation",
              "payroll",
              "tax_return",
              null
            ]
          },
          "sourceId": {
            "type": [
              "string",
              "null"
            ]
          },
          "reversesEntryId": {
            "type": [
              "string",
              "null"
            ]
          },
          "reversedByEntryId": {
            "type": [
              "string",
              "null"
            ]
          },
          "postedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "totalMinor": {
            "type": "integer"
          },
          "lines": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/JournalLine"
            }
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "fiscalYearId",
          "number",
          "date",
          "description",
          "kind",
          "status",
          "sourceType",
          "sourceId",
          "reversesEntryId",
          "reversedByEntryId",
          "postedAt",
          "totalMinor",
          "lines",
          "version"
        ]
      },
      "JournalLine": {
        "type": "object",
        "properties": {
          "lineNo": {
            "type": "integer"
          },
          "accountId": {
            "type": "string"
          },
          "accountCode": {
            "type": "string"
          },
          "accountName": {
            "type": "string"
          },
          "debitMinor": {
            "type": "integer"
          },
          "creditMinor": {
            "type": "integer"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "lineNo",
          "accountId",
          "accountCode",
          "accountName",
          "debitMinor",
          "creditMinor",
          "description"
        ]
      },
      "Company": {
        "type": "object",
        "properties": {
          "legalForm": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "sl",
              "slu",
              "sa",
              "sau",
              "other",
              null
            ]
          },
          "incorporatedOn": {
            "type": [
              "string",
              "null"
            ]
          },
          "shareCapitalMinor": {
            "type": [
              "integer",
              "null"
            ]
          },
          "registryCity": {
            "type": [
              "string",
              "null"
            ]
          },
          "registryVolume": {
            "type": [
              "string",
              "null"
            ]
          },
          "registryFolio": {
            "type": [
              "string",
              "null"
            ]
          },
          "registrySheet": {
            "type": [
              "string",
              "null"
            ]
          },
          "registryEntry": {
            "type": [
              "string",
              "null"
            ]
          },
          "officers": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "taxId": {
                  "type": "string"
                },
                "role": {
                  "type": "string",
                  "enum": [
                    "sole_director",
                    "joint_several_director",
                    "joint_director",
                    "board_chair",
                    "board_secretary",
                    "board_member"
                  ]
                },
                "representativeName": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "appointedOn": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "termEndsOn": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "name",
                "taxId",
                "role",
                "representativeName",
                "appointedOn",
                "termEndsOn"
              ]
            }
          },
          "partners": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "taxId": {
                  "type": "string"
                },
                "kind": {
                  "type": "string",
                  "enum": [
                    "person",
                    "company"
                  ]
                },
                "ownershipBp": {
                  "type": "integer"
                },
                "shares": {
                  "type": [
                    "integer",
                    "null"
                  ]
                }
              },
              "required": [
                "name",
                "taxId",
                "kind",
                "ownershipBp",
                "shares"
              ]
            }
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "legalForm",
          "incorporatedOn",
          "shareCapitalMinor",
          "registryCity",
          "registryVolume",
          "registryFolio",
          "registrySheet",
          "registryEntry",
          "officers",
          "partners",
          "version"
        ]
      },
      "ImportBatch": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "entity": {
            "type": "string",
            "enum": [
              "contacts",
              "products",
              "invoices",
              "purchases",
              "sales"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "queued",
              "running",
              "done",
              "failed",
              "undone"
            ]
          },
          "fileName": {
            "type": "string"
          },
          "format": {
            "type": "string",
            "enum": [
              "csv",
              "xlsx",
              "xls",
              "ods"
            ]
          },
          "sheet": {
            "type": [
              "string",
              "null"
            ]
          },
          "totalRows": {
            "type": "integer"
          },
          "created": {
            "type": "integer"
          },
          "duplicates": {
            "type": "integer"
          },
          "rejected": {
            "type": "integer"
          },
          "contactsCreated": {
            "type": "integer"
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "canUndo": {
            "type": "boolean"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "finishedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "undoneAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "entity",
          "status",
          "fileName",
          "format",
          "sheet",
          "totalRows",
          "created",
          "duplicates",
          "rejected",
          "contactsCreated",
          "error",
          "canUndo",
          "createdAt",
          "finishedAt",
          "undoneAt"
        ]
      },
      "ImportAnalysis": {
        "type": "object",
        "properties": {
          "profile": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "source": {
                "type": "string",
                "enum": [
                  "aeat",
                  "holded",
                  "quipu",
                  "contasimple",
                  "billin",
                  "anfix",
                  "facturadirecta",
                  "sage50",
                  "sage200",
                  "sageactive",
                  "a3",
                  "declarando",
                  "cuentica",
                  "factorial",
                  "zoho",
                  "gestoria"
                ]
              },
              "status": {
                "type": "string",
                "enum": [
                  "documented",
                  "unverified"
                ]
              }
            },
            "required": [
              "id",
              "source",
              "status"
            ],
            "description": "Perfil del programa de origen reconocido en el fichero (M7-T09b)"
          },
          "sheets": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sheet": {
            "type": "string"
          },
          "headerRow": {
            "type": "integer"
          },
          "rowCount": {
            "type": "integer"
          },
          "columns": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "header": {
                  "type": "string"
                },
                "samples": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "index",
                "header",
                "samples"
              ]
            }
          },
          "mapping": {
            "type": "object",
            "additionalProperties": {
              "type": [
                "integer",
                "null"
              ]
            }
          }
        },
        "required": [
          "profile",
          "sheets",
          "sheet",
          "headerRow",
          "rowCount",
          "columns",
          "mapping"
        ]
      },
      "ImportPreview": {
        "type": "object",
        "properties": {
          "totalRows": {
            "type": "integer"
          },
          "okRows": {
            "type": "integer"
          },
          "errorRows": {
            "type": "integer"
          },
          "duplicateRows": {
            "type": "integer"
          },
          "documents": {
            "type": "integer",
            "description": "Contactos, productos o documentos que se crearían"
          },
          "rows": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "row": {
                  "type": "integer"
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "ok",
                    "error",
                    "duplicate"
                  ]
                },
                "issues": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "field": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "code": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "field",
                      "code"
                    ]
                  }
                },
                "values": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "row",
                "status",
                "issues",
                "values"
              ]
            }
          },
          "rejected": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "row": {
                  "type": "integer"
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "ok",
                    "error",
                    "duplicate"
                  ]
                },
                "issues": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "field": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "code": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "field",
                      "code"
                    ]
                  }
                },
                "values": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "row",
                "status",
                "issues",
                "values"
              ]
            }
          },
          "cashWithoutPaidDate": {
            "type": "integer",
            "description": "Facturas del histórico con criterio de caja y sin fecha de cobro: su IVA se declara al registrar el cobro o el 31 de diciembre del año siguiente"
          },
          "nextNumbers": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "seriesId": {
                  "type": "string",
                  "format": "uuid"
                },
                "year": {
                  "type": "integer"
                },
                "next": {
                  "type": "integer"
                },
                "minimum": {
                  "type": "integer"
                },
                "formatted": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "problem": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "enum": [
                    "series_not_found",
                    "next_number_taken",
                    null
                  ]
                }
              },
              "required": [
                "seriesId",
                "year",
                "next",
                "minimum",
                "formatted",
                "problem"
              ]
            }
          }
        },
        "required": [
          "totalRows",
          "okRows",
          "errorRows",
          "duplicateRows",
          "documents",
          "rows",
          "rejected",
          "cashWithoutPaidDate",
          "nextNumbers"
        ]
      },
      "SalesChannel": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "shopify",
              "amazon",
              "stripe",
              "other"
            ]
          },
          "name": {
            "type": "string"
          },
          "mode": {
            "type": "string",
            "enum": [
              "slaupy_invoices",
              "already_invoiced"
            ]
          },
          "feeSupplierContactId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "archived": {
            "type": "boolean"
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "kind",
          "name",
          "mode",
          "feeSupplierContactId",
          "archived",
          "version"
        ]
      },
      "ReconciliationInboxItem": {
        "type": "object",
        "properties": {
          "transaction": {
            "$ref": "#/components/schemas/BankTransaction"
          },
          "candidates": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MatchCandidate"
            }
          },
          "probable": {
            "type": "boolean"
          },
          "aiExplanation": {
            "type": [
              "string",
              "null"
            ]
          },
          "ruleProposal": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "ruleId": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "action": {
                "type": "string",
                "enum": [
                  "expense",
                  "ignore"
                ]
              },
              "categoryCode": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "ruleId",
              "name",
              "action",
              "categoryCode"
            ]
          }
        },
        "required": [
          "transaction",
          "candidates",
          "probable",
          "aiExplanation",
          "ruleProposal"
        ]
      },
      "BankTransaction": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "accountId": {
            "type": "string",
            "format": "uuid"
          },
          "source": {
            "type": "string",
            "enum": [
              "file",
              "provider"
            ]
          },
          "statementId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "operationDate": {
            "type": "string",
            "format": "date"
          },
          "valueDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "amountMinor": {
            "type": "integer",
            "description": "Positivo: entra dinero; negativo: sale"
          },
          "currency": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "counterpartyName": {
            "type": [
              "string",
              "null"
            ]
          },
          "counterpartyIban": {
            "type": [
              "string",
              "null"
            ]
          },
          "reference": {
            "type": [
              "string",
              "null"
            ]
          },
          "commonConcept": {
            "type": [
              "string",
              "null"
            ]
          },
          "ownConcept": {
            "type": [
              "string",
              "null"
            ]
          },
          "documentNumber": {
            "type": [
              "string",
              "null"
            ]
          },
          "originalCurrency": {
            "type": [
              "string",
              "null"
            ]
          },
          "originalAmount": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "matched",
              "ignored"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "accountId",
          "source",
          "statementId",
          "operationDate",
          "valueDate",
          "amountMinor",
          "currency",
          "description",
          "counterpartyName",
          "counterpartyIban",
          "reference",
          "commonConcept",
          "ownConcept",
          "documentNumber",
          "originalCurrency",
          "originalAmount",
          "status",
          "createdAt"
        ]
      },
      "MatchCandidate": {
        "type": "object",
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "invoice",
              "purchase",
              "channel_settlement",
              "own_transfer"
            ]
          },
          "targetId": {
            "type": "string"
          },
          "amountMinor": {
            "type": "integer"
          },
          "score": {
            "type": "integer"
          },
          "reasons": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "origin": {
            "type": "string",
            "enum": [
              "rules",
              "ai"
            ]
          },
          "group": {
            "type": [
              "string",
              "null"
            ]
          },
          "number": {
            "type": [
              "string",
              "null"
            ]
          },
          "counterparty": {
            "type": [
              "string",
              "null"
            ]
          },
          "pendingMinor": {
            "type": [
              "integer",
              "null"
            ]
          }
        },
        "required": [
          "kind",
          "targetId",
          "amountMinor",
          "score",
          "reasons",
          "origin",
          "group",
          "number",
          "counterparty",
          "pendingMinor"
        ]
      },
      "ReconciliationPart": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "target": {
            "type": "string",
            "enum": [
              "invoice",
              "purchase",
              "own_transfer"
            ]
          },
          "targetId": {
            "type": "string"
          },
          "paymentId": {
            "type": [
              "string",
              "null"
            ]
          },
          "amountMinor": {
            "type": "integer"
          },
          "origin": {
            "type": "string",
            "enum": [
              "suggestion",
              "manual",
              "rule",
              "ai"
            ]
          },
          "createdAt": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "target",
          "targetId",
          "paymentId",
          "amountMinor",
          "origin",
          "createdAt"
        ]
      },
      "BankRule": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "enabled": {
            "type": "boolean"
          },
          "autoConfirm": {
            "type": "boolean"
          },
          "priority": {
            "type": "integer"
          },
          "direction": {
            "type": "string",
            "enum": [
              "in",
              "out",
              "any"
            ]
          },
          "textContains": {
            "type": "string"
          },
          "bankAccountId": {
            "type": [
              "string",
              "null"
            ]
          },
          "amountMinMinor": {
            "type": [
              "integer",
              "null"
            ]
          },
          "amountMaxMinor": {
            "type": [
              "integer",
              "null"
            ]
          },
          "action": {
            "type": "string",
            "enum": [
              "expense",
              "ignore"
            ]
          },
          "categoryCode": {
            "type": [
              "string",
              "null"
            ]
          },
          "supplierName": {
            "type": [
              "string",
              "null"
            ]
          },
          "contactId": {
            "type": [
              "string",
              "null"
            ]
          },
          "appliedCount": {
            "type": "integer"
          },
          "lastAppliedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "name",
          "enabled",
          "autoConfirm",
          "priority",
          "direction",
          "textContains",
          "bankAccountId",
          "amountMinMinor",
          "amountMaxMinor",
          "action",
          "categoryCode",
          "supplierName",
          "contactId",
          "appliedCount",
          "lastAppliedAt",
          "version"
        ]
      },
      "BankAccount": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "iban": {
            "type": [
              "string",
              "null"
            ]
          },
          "ibanMasked": {
            "type": [
              "string",
              "null"
            ]
          },
          "bankCode": {
            "type": [
              "string",
              "null"
            ]
          },
          "branchCode": {
            "type": [
              "string",
              "null"
            ]
          },
          "accountNumber": {
            "type": [
              "string",
              "null"
            ]
          },
          "currency": {
            "type": "string"
          },
          "holderName": {
            "type": [
              "string",
              "null"
            ]
          },
          "balanceMinor": {
            "type": [
              "integer",
              "null"
            ]
          },
          "balanceDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "connectionId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "archived": {
            "type": "boolean"
          },
          "transactionCount": {
            "type": "integer"
          },
          "lastOperationDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "version": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "name",
          "iban",
          "ibanMasked",
          "bankCode",
          "branchCode",
          "accountNumber",
          "currency",
          "holderName",
          "balanceMinor",
          "balanceDate",
          "connectionId",
          "archived",
          "transactionCount",
          "lastOperationDate",
          "version",
          "createdAt"
        ]
      },
      "BankTransactionPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BankTransaction"
            }
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          },
          "totals": {
            "type": "object",
            "properties": {
              "count": {
                "type": "integer"
              },
              "inMinor": {
                "type": "integer"
              },
              "outMinor": {
                "type": "integer"
              }
            },
            "required": [
              "count",
              "inMinor",
              "outMinor"
            ]
          }
        },
        "required": [
          "items",
          "nextCursor",
          "totals"
        ]
      },
      "BankStatement": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "fileName": {
            "type": "string"
          },
          "format": {
            "type": "string",
            "enum": [
              "n43",
              "csv",
              "xlsx",
              "xls",
              "ods"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "queued",
              "done",
              "failed",
              "undone"
            ]
          },
          "profile": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "bank": {
                "type": "string"
              },
              "verified": {
                "type": "boolean"
              }
            },
            "required": [
              "id",
              "bank",
              "verified"
            ],
            "description": "Perfil del banco reconocido en una hoja de cálculo (⚠ sin verificar con fichero real)"
          },
          "sheet": {
            "type": [
              "string",
              "null"
            ]
          },
          "balanceChecked": {
            "type": "boolean"
          },
          "periodFrom": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "periodTo": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "movementCount": {
            "type": "integer"
          },
          "accounts": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "key": {
                  "type": "string"
                },
                "bankCode": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "branchCode": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "accountNumber": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "holderName": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "currency": {
                  "type": "string"
                },
                "startDate": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date"
                },
                "endDate": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date"
                },
                "openingBalanceMinor": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "closingBalanceMinor": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "movements": {
                  "type": "integer"
                },
                "debitMinor": {
                  "type": "integer"
                },
                "creditMinor": {
                  "type": "integer"
                },
                "suggestedAccountId": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid"
                },
                "accountId": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid",
                  "description": "Cuenta en la que quedó, una vez importado"
                },
                "inserted": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "duplicates": {
                  "type": [
                    "integer",
                    "null"
                  ]
                }
              },
              "required": [
                "key",
                "bankCode",
                "branchCode",
                "accountNumber",
                "holderName",
                "currency",
                "startDate",
                "endDate",
                "openingBalanceMinor",
                "closingBalanceMinor",
                "movements",
                "debitMinor",
                "creditMinor",
                "suggestedAccountId",
                "accountId",
                "inserted",
                "duplicates"
              ]
            }
          },
          "inserted": {
            "type": "integer"
          },
          "duplicates": {
            "type": "integer"
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "canUndo": {
            "type": "boolean"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "finishedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "undoneAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "fileName",
          "format",
          "status",
          "profile",
          "sheet",
          "balanceChecked",
          "periodFrom",
          "periodTo",
          "movementCount",
          "accounts",
          "inserted",
          "duplicates",
          "error",
          "canUndo",
          "createdAt",
          "finishedAt",
          "undoneAt"
        ]
      },
      "BankStatementPreview": {
        "type": "object",
        "properties": {
          "statement": {
            "$ref": "#/components/schemas/BankStatement"
          },
          "parts": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "key": {
                  "type": "string"
                },
                "suggestedAccountId": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid"
                },
                "alreadyImported": {
                  "type": "integer"
                },
                "sample": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "operationDate": {
                        "type": "string",
                        "format": "date"
                      },
                      "valueDate": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "format": "date"
                      },
                      "amountMinor": {
                        "type": "integer"
                      },
                      "description": {
                        "type": "string"
                      },
                      "counterpartyName": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "reference": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    },
                    "required": [
                      "operationDate",
                      "valueDate",
                      "amountMinor",
                      "description",
                      "counterpartyName",
                      "reference"
                    ]
                  }
                }
              },
              "required": [
                "key",
                "suggestedAccountId",
                "alreadyImported",
                "sample"
              ]
            }
          }
        },
        "required": [
          "statement",
          "parts"
        ]
      },
      "BankConnection": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "provider": {
            "type": "string",
            "enum": [
              "file",
              "sandbox",
              "enable_banking",
              "tink",
              "yapily",
              "salt_edge",
              "unnax"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "active",
              "expired",
              "revoked",
              "error"
            ]
          },
          "institutionName": {
            "type": [
              "string",
              "null"
            ]
          },
          "consentExpiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "lastSyncedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "lastSyncError": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "provider",
          "status",
          "institutionName",
          "consentExpiresAt",
          "lastSyncedAt",
          "lastSyncError",
          "createdAt"
        ]
      },
      "VerifactuStatus": {
        "type": "object",
        "properties": {
          "installation": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "number": {
                "type": "string"
              },
              "status": {
                "type": "string",
                "enum": [
                  "local",
                  "active",
                  "retired"
                ]
              },
              "environment": {
                "type": "string",
                "enum": [
                  "test",
                  "production"
                ]
              },
              "activatedAt": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "nextSendAt": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "lastSendError": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "certificateId": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "verifiedAt": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "integrityProblem": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "integrityBrokenSeq": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            },
            "required": [
              "id",
              "number",
              "status",
              "environment",
              "activatedAt",
              "nextSendAt",
              "lastSendError",
              "certificateId",
              "verifiedAt",
              "integrityProblem",
              "integrityBrokenSeq"
            ]
          },
          "counts": {
            "type": "object",
            "additionalProperties": {
              "type": "integer"
            }
          },
          "pending": {
            "type": "integer"
          },
          "openIncident": {
            "$ref": "#/components/schemas/VerifactuIncident"
          }
        },
        "required": [
          "installation",
          "counts",
          "pending",
          "openIncident"
        ]
      },
      "VerifactuIncident": {
        "type": [
          "object",
          "null"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "cause": {
            "type": "string"
          },
          "message": {
            "type": [
              "string",
              "null"
            ]
          },
          "startedAt": {
            "type": "string"
          },
          "endedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "recordsAffected": {
            "type": "integer"
          },
          "attempts": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "cause",
          "message",
          "startedAt",
          "endedAt",
          "recordsAffected",
          "attempts"
        ]
      },
      "VerifactuEvent": {
        "type": "object",
        "properties": {
          "seq": {
            "type": "integer"
          },
          "type": {
            "type": "string"
          },
          "details": {
            "type": [
              "string",
              "null"
            ]
          },
          "generatedAt": {
            "type": "string"
          },
          "hash": {
            "type": "string"
          }
        },
        "required": [
          "seq",
          "type",
          "details",
          "generatedAt",
          "hash"
        ]
      },
      "VerifactuRecord": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "seq": {
            "type": "integer"
          },
          "kind": {
            "type": "string",
            "enum": [
              "alta",
              "anulacion"
            ]
          },
          "invoiceId": {
            "type": "string"
          },
          "seriesNumber": {
            "type": "string"
          },
          "issueDate": {
            "type": "string"
          },
          "invoiceType": {
            "type": [
              "string",
              "null"
            ]
          },
          "total": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "local",
              "pending",
              "sending",
              "sent",
              "accepted",
              "accepted_with_errors",
              "rejected"
            ]
          },
          "aeatCode": {
            "type": [
              "string",
              "null"
            ]
          },
          "aeatMessage": {
            "type": [
              "string",
              "null"
            ]
          },
          "errorFamily": {
            "type": [
              "string",
              "null"
            ]
          },
          "needsAction": {
            "type": "boolean"
          },
          "isCorrection": {
            "type": "boolean"
          },
          "incident": {
            "type": "boolean"
          },
          "generatedAt": {
            "type": "string"
          },
          "sentAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "attempts": {
            "type": "integer"
          },
          "hash": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "seq",
          "kind",
          "invoiceId",
          "seriesNumber",
          "issueDate",
          "invoiceType",
          "total",
          "status",
          "aeatCode",
          "aeatMessage",
          "errorFamily",
          "needsAction",
          "isCorrection",
          "incident",
          "generatedAt",
          "sentAt",
          "attempts",
          "hash"
        ]
      },
      "VerifactuRecordDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/VerifactuRecord"
          },
          {
            "type": "object",
            "properties": {
              "xml": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "csv": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "submission": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string"
                  },
                  "outcome": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "csv": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "startedAt": {
                    "type": "string"
                  },
                  "finishedAt": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "response": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "id",
                  "status",
                  "outcome",
                  "csv",
                  "startedAt",
                  "finishedAt",
                  "response"
                ]
              }
            },
            "required": [
              "xml",
              "csv",
              "submission"
            ]
          }
        ]
      },
      "ExportVerifactuRecords": {
        "type": "object",
        "properties": {
          "from": {
            "type": "string"
          },
          "to": {
            "type": "string"
          }
        },
        "required": [
          "from",
          "to"
        ],
        "additionalProperties": false
      },
      "OrgFeatures": {
        "type": "object",
        "properties": {
          "features": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "bank_file",
                "bank",
                "api",
                "mcp",
                "mcp_write",
                "channels",
                "accounting",
                "firm",
                "firm_accounting_export",
                "advisor_access",
                "approvals",
                "payment_batches",
                "email_inbox",
                "treasury",
                "receivables",
                "einvoice",
                "annual_income",
                "territory_taxes",
                "corporate_tax",
                "roadmap",
                "help_assistant",
                "irpf_rdl_43_2026",
                "referrals",
                "refund_guarantee"
              ]
            },
            "description": "Funciones nuevas encendidas para la organización (las apagadas no se muestran)"
          }
        },
        "required": [
          "features"
        ]
      },
      "SearchResult": {
        "type": "object",
        "properties": {
          "groups": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "invoices",
                    "quotes",
                    "deliveryNotes",
                    "contacts",
                    "products",
                    "purchases",
                    "assets",
                    "taxReturns"
                  ]
                },
                "items": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/SearchItem"
                  }
                },
                "more": {
                  "type": "boolean"
                }
              },
              "required": [
                "type",
                "items",
                "more"
              ]
            }
          }
        },
        "required": [
          "groups"
        ]
      },
      "SearchItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": [
              "string",
              "null"
            ]
          },
          "subtitle": {
            "type": [
              "string",
              "null"
            ]
          },
          "date": {
            "type": [
              "string",
              "null"
            ]
          },
          "amountMinor": {
            "type": [
              "integer",
              "null"
            ]
          },
          "currency": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": [
              "string",
              "null"
            ]
          },
          "model": {
            "type": [
              "string",
              "null"
            ]
          },
          "period": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "title",
          "subtitle",
          "date",
          "amountMinor",
          "currency",
          "status",
          "model",
          "period"
        ]
      },
      "OrganizationExport": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "ready",
              "failed"
            ]
          },
          "sizeBytes": {
            "type": [
              "integer",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "completedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "expiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "status",
          "sizeBytes",
          "createdAt",
          "completedAt",
          "expiresAt"
        ]
      },
      "WebhookEndpoint": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "url": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "enabled": {
            "type": "boolean"
          },
          "disabledReason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "failing",
              "manual",
              null
            ]
          },
          "disabledAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "failingSince": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "secretFingerprint": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "url",
          "description",
          "events",
          "enabled",
          "disabledReason",
          "disabledAt",
          "failingSince",
          "secretFingerprint",
          "createdAt",
          "version"
        ]
      },
      "WebhookEndpointWithSecret": {
        "type": "object",
        "properties": {
          "endpoint": {
            "$ref": "#/components/schemas/WebhookEndpoint"
          },
          "secret": {
            "type": "string"
          }
        },
        "required": [
          "endpoint",
          "secret"
        ],
        "description": "El secreto de firma (`whsec_…`) solo se devuelve al crear o al rotar."
      },
      "WebhookDelivery": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "eventId": {
            "type": "string",
            "format": "uuid"
          },
          "eventType": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "succeeded",
              "failed"
            ]
          },
          "attempts": {
            "type": "integer"
          },
          "nextAttemptAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "lastAttemptAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "responseStatus": {
            "type": [
              "integer",
              "null"
            ]
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "durationMs": {
            "type": [
              "integer",
              "null"
            ]
          },
          "deliveredAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "resendOf": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "payload": {}
        },
        "required": [
          "id",
          "eventId",
          "eventType",
          "status",
          "attempts",
          "nextAttemptAt",
          "lastAttemptAt",
          "responseStatus",
          "error",
          "durationMs",
          "deliveredAt",
          "resendOf",
          "createdAt"
        ]
      },
      "Receivables": {
        "type": "object",
        "properties": {
          "asOf": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "interestEnabled": {
            "type": "boolean"
          },
          "totals": {
            "type": "object",
            "properties": {
              "outstandingMinor": {
                "type": "integer"
              },
              "overdueMinor": {
                "type": "integer"
              }
            },
            "required": [
              "outstandingMinor",
              "overdueMinor"
            ]
          },
          "buckets": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "bucket": {
                  "type": "string",
                  "enum": [
                    "current",
                    "d1_30",
                    "d31_60",
                    "d61_90",
                    "d90_plus"
                  ]
                },
                "totalMinor": {
                  "type": "integer"
                },
                "count": {
                  "type": "integer"
                }
              },
              "required": [
                "bucket",
                "totalMinor",
                "count"
              ]
            }
          },
          "customers": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "contactId": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid"
                },
                "name": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "label": {
                  "type": "string",
                  "enum": [
                    "puntual",
                    "a_veces_tarde",
                    "moroso_habitual",
                    "sin_historial"
                  ]
                },
                "averageDelayDays": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "outstandingMinor": {
                  "type": "integer"
                },
                "overdueMinor": {
                  "type": "integer"
                },
                "invoices": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "number": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "issueDate": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "dueDate": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "daysLate": {
                        "type": "integer"
                      },
                      "bucket": {
                        "type": "string",
                        "enum": [
                          "current",
                          "d1_30",
                          "d31_60",
                          "d61_90",
                          "d90_plus"
                        ]
                      },
                      "outstandingMinor": {
                        "type": "integer"
                      },
                      "consumer": {
                        "type": "boolean"
                      },
                      "disputed": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "interest": {
                        "$ref": "#/components/schemas/LateInterest"
                      }
                    },
                    "required": [
                      "id",
                      "number",
                      "issueDate",
                      "dueDate",
                      "daysLate",
                      "bucket",
                      "outstandingMinor",
                      "consumer",
                      "disputed",
                      "interest"
                    ]
                  }
                }
              },
              "required": [
                "contactId",
                "name",
                "label",
                "averageDelayDays",
                "outstandingMinor",
                "overdueMinor",
                "invoices"
              ]
            }
          }
        },
        "required": [
          "asOf",
          "currency",
          "interestEnabled",
          "totals",
          "buckets",
          "customers"
        ]
      },
      "LateInterest": {
        "type": [
          "object",
          "null"
        ],
        "properties": {
          "interestMinor": {
            "type": "integer"
          },
          "compensationMinor": {
            "type": "integer"
          },
          "spans": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "from": {
                  "type": "string"
                },
                "to": {
                  "type": "string"
                },
                "days": {
                  "type": "integer"
                },
                "principalMinor": {
                  "type": "integer"
                },
                "rate": {
                  "type": "string"
                },
                "interestMinor": {
                  "type": "integer"
                }
              },
              "required": [
                "from",
                "to",
                "days",
                "principalMinor",
                "rate",
                "interestMinor"
              ]
            }
          },
          "missingRates": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "interestMinor",
          "compensationMinor",
          "spans",
          "missingRates"
        ]
      },
      "PaymentProfile": {
        "type": "object",
        "properties": {
          "label": {
            "type": "string",
            "enum": [
              "puntual",
              "a_veces_tarde",
              "moroso_habitual",
              "sin_historial"
            ]
          },
          "averageDelayDays": {
            "type": [
              "integer",
              "null"
            ]
          },
          "invoices": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "number": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "dueDate": {
                  "type": "string"
                },
                "paidOn": {
                  "type": "string"
                },
                "delayDays": {
                  "type": "integer"
                }
              },
              "required": [
                "id",
                "number",
                "dueDate",
                "paidOn",
                "delayDays"
              ]
            }
          }
        },
        "required": [
          "label",
          "averageDelayDays",
          "invoices"
        ]
      },
      "PaymentReminder": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "invoiceId": {
            "type": "string",
            "format": "uuid"
          },
          "invoiceNumber": {
            "type": [
              "string",
              "null"
            ]
          },
          "customer": {
            "type": [
              "string",
              "null"
            ]
          },
          "level": {
            "type": "integer"
          },
          "tone": {
            "type": "string",
            "enum": [
              "friendly",
              "neutral",
              "firm"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "suggested",
              "sent",
              "dismissed",
              "cancelled"
            ]
          },
          "to": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "subject": {
            "type": "string"
          },
          "body": {
            "type": "string"
          },
          "outstandingMinor": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "decidedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "invoiceId",
          "invoiceNumber",
          "customer",
          "level",
          "tone",
          "status",
          "to",
          "subject",
          "body",
          "outstandingMinor",
          "createdAt",
          "decidedAt",
          "version"
        ]
      },
      "DunningPolicy": {
        "type": "object",
        "properties": {
          "enabled": {
            "type": "boolean"
          },
          "level1Days": {
            "type": "integer"
          },
          "level2Days": {
            "type": "integer"
          },
          "level3Days": {
            "type": "integer"
          }
        },
        "required": [
          "enabled",
          "level1Days",
          "level2Days",
          "level3Days"
        ]
      },
      "ReceivableEscalation": {
        "type": "object",
        "properties": {
          "invoiceId": {
            "type": "string",
            "format": "uuid"
          },
          "steps": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "step": {
                  "type": "string",
                  "enum": [
                    "demand",
                    "burofax",
                    "monitorio",
                    "insolvency"
                  ]
                },
                "occurredOn": {
                  "type": "string"
                },
                "note": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "fileId": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid"
                },
                "createdAt": {
                  "type": "string",
                  "format": "date-time"
                }
              },
              "required": [
                "id",
                "step",
                "occurredOn",
                "note",
                "fileId",
                "createdAt"
              ]
            }
          },
          "badDebt": {
            "type": "object",
            "properties": {
              "status": {
                "type": "string",
                "enum": [
                  "not_eligible",
                  "not_yet",
                  "open",
                  "closed"
                ]
              },
              "route": {
                "type": "string",
                "enum": [
                  "uncollectable",
                  "insolvency"
                ]
              },
              "missing": {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "time",
                    "claim",
                    "min_amount",
                    "debtor_established"
                  ]
                }
              },
              "opensOn": {
                "type": "string"
              },
              "closesOn": {
                "type": "string"
              },
              "daysLeft": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "communicationMonths": {
                "type": "integer"
              },
              "exclusions": {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "secured",
                    "related_party",
                    "not_established"
                  ]
                }
              },
              "citation": {
                "type": "string"
              }
            },
            "required": [
              "status",
              "route",
              "missing",
              "opensOn",
              "closesOn",
              "daysLeft",
              "communicationMonths",
              "exclusions",
              "citation"
            ]
          },
          "disclaimer": {
            "type": "string"
          }
        },
        "required": [
          "invoiceId",
          "steps",
          "badDebt",
          "disclaimer"
        ]
      },
      "MonthChecklist": {
        "type": "object",
        "properties": {
          "year": {
            "type": "integer"
          },
          "month": {
            "type": "integer"
          },
          "from": {
            "type": "string"
          },
          "to": {
            "type": "string"
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "key": {
                  "type": "string",
                  "enum": [
                    "draft_invoices",
                    "delivered_notes",
                    "accepted_quotes",
                    "inbox_pending",
                    "draft_purchases",
                    "overdue_invoices",
                    "overdue_purchases",
                    "bank_unreconciled",
                    "verifactu_pending",
                    "invalid_tax_ids"
                  ]
                },
                "count": {
                  "type": "integer"
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "ok",
                    "pending",
                    "not_applicable"
                  ]
                },
                "link": {
                  "type": "string"
                }
              },
              "required": [
                "key",
                "count",
                "status",
                "link"
              ]
            }
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "reviewed",
              "reopened"
            ]
          },
          "reviewed": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "by": {
                "type": "string",
                "format": "uuid"
              },
              "at": {
                "type": "string",
                "format": "date-time"
              }
            },
            "required": [
              "by",
              "at"
            ]
          },
          "lateDocuments": {
            "type": "integer"
          },
          "readOnly": {
            "type": "boolean"
          },
          "quarterEnd": {
            "type": "boolean"
          }
        },
        "required": [
          "year",
          "month",
          "from",
          "to",
          "items",
          "status",
          "reviewed",
          "lateDocuments",
          "readOnly",
          "quarterEnd"
        ]
      },
      "TreasuryForecast": {
        "type": "object",
        "properties": {
          "today": {
            "type": "string"
          },
          "horizonDays": {
            "type": "integer"
          },
          "currency": {
            "type": "string"
          },
          "opening": {
            "type": "object",
            "properties": {
              "balanceMinor": {
                "type": "integer"
              },
              "source": {
                "type": "string",
                "enum": [
                  "manual",
                  "bank",
                  "none"
                ]
              },
              "date": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "balanceMinor",
              "source",
              "date"
            ]
          },
          "movements": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "key": {
                  "type": "string"
                },
                "date": {
                  "type": "string"
                },
                "amountMinor": {
                  "type": "integer"
                },
                "source": {
                  "type": "string",
                  "enum": [
                    "invoice",
                    "recurring_invoice",
                    "quote",
                    "purchase",
                    "payment_batch",
                    "recurring_expense",
                    "self_employed_fee",
                    "tax"
                  ]
                },
                "certainty": {
                  "type": "string",
                  "enum": [
                    "known",
                    "expected",
                    "estimated"
                  ]
                },
                "label": {
                  "type": "string"
                },
                "ref": {
                  "type": [
                    "object",
                    "null"
                  ],
                  "properties": {
                    "type": {
                      "type": "string"
                    },
                    "id": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "id"
                  ]
                },
                "excluded": {
                  "type": "boolean"
                },
                "moved": {
                  "type": "boolean"
                },
                "prudent": {
                  "type": "boolean"
                },
                "origin": {
                  "type": "string",
                  "enum": [
                    "auto",
                    "manual"
                  ]
                }
              },
              "required": [
                "key",
                "date",
                "amountMinor",
                "source",
                "certainty",
                "label",
                "ref",
                "excluded",
                "moved",
                "prudent"
              ]
            }
          },
          "expected": {
            "type": "object",
            "properties": {
              "weeks": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "start": {
                      "type": "string"
                    },
                    "end": {
                      "type": "string"
                    },
                    "inMinor": {
                      "type": "integer"
                    },
                    "outMinor": {
                      "type": "integer"
                    },
                    "balanceMinor": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "start",
                    "end",
                    "inMinor",
                    "outMinor",
                    "balanceMinor"
                  ]
                }
              },
              "segments": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "fromDay": {
                      "type": "integer"
                    },
                    "toDay": {
                      "type": "integer"
                    },
                    "inMinor": {
                      "type": "integer"
                    },
                    "outMinor": {
                      "type": "integer"
                    },
                    "balanceMinor": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "fromDay",
                    "toDay",
                    "inMinor",
                    "outMinor",
                    "balanceMinor"
                  ]
                }
              },
              "inMinor": {
                "type": "integer"
              },
              "outMinor": {
                "type": "integer"
              },
              "finalBalanceMinor": {
                "type": "integer"
              },
              "firstNegative": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "date": {
                    "type": "string"
                  },
                  "balanceMinor": {
                    "type": "integer"
                  },
                  "causeKey": {
                    "type": "string"
                  }
                },
                "required": [
                  "date",
                  "balanceMinor",
                  "causeKey"
                ]
              }
            },
            "required": [
              "weeks",
              "segments",
              "inMinor",
              "outMinor",
              "finalBalanceMinor",
              "firstNegative"
            ]
          },
          "prudent": {
            "type": "object",
            "properties": {
              "weeks": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "start": {
                      "type": "string"
                    },
                    "end": {
                      "type": "string"
                    },
                    "inMinor": {
                      "type": "integer"
                    },
                    "outMinor": {
                      "type": "integer"
                    },
                    "balanceMinor": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "start",
                    "end",
                    "inMinor",
                    "outMinor",
                    "balanceMinor"
                  ]
                }
              },
              "segments": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "fromDay": {
                      "type": "integer"
                    },
                    "toDay": {
                      "type": "integer"
                    },
                    "inMinor": {
                      "type": "integer"
                    },
                    "outMinor": {
                      "type": "integer"
                    },
                    "balanceMinor": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "fromDay",
                    "toDay",
                    "inMinor",
                    "outMinor",
                    "balanceMinor"
                  ]
                }
              },
              "inMinor": {
                "type": "integer"
              },
              "outMinor": {
                "type": "integer"
              },
              "finalBalanceMinor": {
                "type": "integer"
              },
              "firstNegative": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "date": {
                    "type": "string"
                  },
                  "balanceMinor": {
                    "type": "integer"
                  },
                  "causeKey": {
                    "type": "string"
                  }
                },
                "required": [
                  "date",
                  "balanceMinor",
                  "causeKey"
                ]
              }
            },
            "required": [
              "weeks",
              "segments",
              "inMinor",
              "outMinor",
              "finalBalanceMinor",
              "firstNegative"
            ]
          }
        },
        "required": [
          "today",
          "horizonDays",
          "currency",
          "opening",
          "movements",
          "expected",
          "prudent"
        ]
      },
      "TreasurySettings": {
        "type": "object",
        "properties": {
          "openingBalanceMinor": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": -100000000000,
            "maximum": 100000000000
          },
          "openingDate": {
            "type": [
              "string",
              "null"
            ]
          },
          "selfEmployedFeeMinor": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 10000000000
          },
          "corporateInstalmentMinor": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 10000000000
          },
          "recurring": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "label": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 80
                },
                "amountMinor": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 10000000000
                },
                "day": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 31
                }
              },
              "required": [
                "label",
                "amountMinor",
                "day"
              ]
            },
            "maxItems": 30
          },
          "adjustments": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "key": {
                  "type": "string",
                  "minLength": 3,
                  "maxLength": 120
                },
                "excluded": {
                  "type": "boolean"
                },
                "date": {
                  "type": "string"
                }
              },
              "required": [
                "key"
              ]
            },
            "maxItems": 500
          }
        },
        "required": [
          "openingBalanceMinor",
          "openingDate",
          "selfEmployedFeeMinor",
          "recurring",
          "adjustments"
        ]
      }
    },
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "slk_live_… / slk_test_…",
        "description": "Clave de API de la organización (`Authorization: Bearer slk_live_…`). Solo sirve en las rutas `/v1/orgs/{orgId}/…` de su organización y con los permisos de sus alcances. Cada respuesta lleva `RateLimit-Limit`, `RateLimit-Remaining` y `RateLimit-Reset`; al agotar el cupo, 429 con `Retry-After`. Las escrituras admiten `Idempotency-Key` (obligatoria en emitir y anular)."
      }
    }
  }
}
