{
  "openapi": "3.1.0",
  "info": {
    "title": "ESSE24 API",
    "version": "1.25.0",
    "description": "REST API per ERP ESSE24. Autenticazione tramite API key Bearer. Il company_id è sempre derivato server-side dalla chiave autenticata, mai dal body della richiesta.",
    "contact": {
      "name": "ESSE24 Support",
      "email": "api@esse24.it"
    }
  },
  "servers": [
    {
      "url": "https://ocjdvpanqhwapwxraney.supabase.co/functions/v1/api-gateway/v1",
      "description": "Produzione e sandbox. L'ambiente lo decide la chiave: esse24_live_ legge l'azienda reale, esse24_test_ la sua azienda sandbox, vuota e con gli stessi moduli (niente invii SDI). Le chiavi sandbox emesse fino al 03-12-2026 iniziano con esse24_sandbox_."
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "tags": [
    {
      "name": "Invoices",
      "description": "Fatture di vendita (sales_invoices)"
    },
    {
      "name": "Customers",
      "description": "Anagrafica clienti"
    },
    {
      "name": "Suppliers",
      "description": "Anagrafica fornitori"
    },
    {
      "name": "Banking",
      "description": "Conti bancari e movimenti"
    },
    {
      "name": "Items",
      "description": "Articoli e servizi (catalogo)"
    },
    {
      "name": "Pricelists",
      "description": "Listini prezzi"
    },
    {
      "name": "Agents",
      "description": "Agenti di vendita"
    },
    {
      "name": "Warehouses",
      "description": "Magazzini"
    },
    {
      "name": "Chart Of Accounts",
      "description": "Piano dei conti"
    },
    {
      "name": "Journal",
      "description": "Giornale contabile"
    },
    {
      "name": "Trial Balance",
      "description": "Bilancio di verifica"
    },
    {
      "name": "Receivables",
      "description": "Scadenzario attivo e passivo"
    },
    {
      "name": "Orders",
      "description": "Ordini di vendita"
    },
    {
      "name": "Quotes",
      "description": "Preventivi"
    },
    {
      "name": "Purchase Orders",
      "description": "Ordini di acquisto"
    },
    {
      "name": "Purchase Delivery Notes",
      "description": "DDT d'acquisto: i resi a fornitore emessi da un sistema esterno e rispecchiati in esse24 (il magazzino non si muove), e la correzione di una riga delle bolle d'arrivo dal portale."
    },
    {
      "name": "Purchase Invoices",
      "description": "Fatture d'acquisto: le fatture e le note di credito dei fornitori registrate in esse24, con le bolle che chiudono e le righe. Sola lettura."
    },
    {
      "name": "Stock Movements",
      "description": "Movimenti di magazzino"
    },
    {
      "name": "Company",
      "description": "Dati aziendali"
    },
    {
      "name": "Delivery Notes",
      "description": "DDT di vendita emessi da un sistema esterno e rispecchiati in esse24. Il documento resta dell'emittente: il numero e l'id esterno arrivano col payload, il magazzino non si muove e la fatturazione differita li raggruppa."
    },
    {
      "name": "Receipts",
      "description": "Chiusure giornaliere dei corrispettivi (scontrini). Una chiusura corrisponde a un Z del registratore telematico: il registro IVA corrispettivi e la scrittura in prima nota li produce il server."
    },
    {
      "name": "Webhooks",
      "description": "Sottoscrizioni webhook"
    },
    {
      "name": "Changes",
      "description": "Registro dei cambiamenti: cosa è cambiato, da recuperare con un cursore"
    }
  ],
  "paths": {
    "/invoices": {
      "get": {
        "operationId": "listInvoices",
        "summary": "Elenca fatture",
        "tags": [
          "Invoices"
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "confirmed",
                "ready_for_sdi",
                "sent_sdi",
                "delivered",
                "rejected",
                "paid"
              ]
            }
          },
          {
            "name": "payment_status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "unpaid",
                "partial",
                "paid"
              ]
            }
          },
          {
            "name": "document_type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "invoice",
                "credit_note",
                "debit_note",
                "receipt",
                "proforma"
              ]
            }
          },
          {
            "name": "customer_id",
            "in": "query",
            "description": "Solo le fatture di questo cliente.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "order_id",
            "in": "query",
            "description": "La fattura che chiude questo ordine di vendita (fattura senza bolla) e le note di credito che la stornano: la fattura è quella con document_type `invoice`. Combinabile con `document_type=invoice`. Le fatture dai DDT non hanno `order_id`: per quelle si passa dalla bolla.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista fatture",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/InvoiceListItem"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "550e8400-e29b-41d4-a716-446655440000",
                      "company_id": "company-uuid",
                      "customer_id": "cust-uuid",
                      "invoice_number": "2026/001",
                      "invoice_date": "2026-06-12",
                      "due_date": "2026-07-12",
                      "status": "confirmed",
                      "subtotal": 1500,
                      "vat_amount": 330,
                      "total_amount": 1830,
                      "stamp_duty": null,
                      "payment_status": "unpaid",
                      "paid_amount": 0,
                      "payment_date": null,
                      "payment_method": null,
                      "sdi_status": null,
                      "sdi_sent_at": null,
                      "payment_terms": "30gg",
                      "notes": null,
                      "document_type": "invoice",
                      "document_subtype": "standard",
                      "posting_status": "posted",
                      "created_at": "2026-06-12T14:30:00.000Z",
                      "updated_at": "2026-06-12T14:30:00.000Z",
                      "created_by": "user-uuid"
                    }
                  ],
                  "meta": {
                    "request_id": "req_8f3a2b1c",
                    "total": 243,
                    "page": 1,
                    "per_page": 20,
                    "total_pages": 13
                  }
                }
              }
            }
          },
          "401": {
            "description": "Non autenticato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Scope mancante (invoices:read)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "invoices:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createInvoice",
        "summary": "Crea fattura",
        "tags": [
          "Invoices"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateInvoiceRequest"
              },
              "example": {
                "customer_id": "550e8400-e29b-41d4-a716-446655440001",
                "invoice_date": "2026-06-12",
                "due_date": "2026-07-12",
                "invoice_number": "2026/042",
                "document_type": "invoice",
                "document_subtype": "standard",
                "payment_terms": "30gg",
                "payment_method": "bank_transfer",
                "notes": "Consulenza giugno 2026",
                "items": [
                  {
                    "line_type": "item",
                    "item_code": "CONS-001",
                    "description": "Consulenza strategica",
                    "quantity": 10,
                    "uom": "H",
                    "unit_price": 150,
                    "discount_percent": 0,
                    "vat_rate": 22
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Fattura creata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/InvoiceResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "550e8400-e29b-41d4-a716-446655440000",
                    "company_id": "company-uuid",
                    "customer_id": "550e8400-e29b-41d4-a716-446655440001",
                    "invoice_number": "2026/042",
                    "invoice_date": "2026-06-12",
                    "due_date": "2026-07-12",
                    "status": "draft",
                    "subtotal": 1500,
                    "vat_amount": 330,
                    "total_amount": 1830,
                    "stamp_duty": null,
                    "payment_status": "unpaid",
                    "paid_amount": 0,
                    "payment_date": null,
                    "payment_method": "bank_transfer",
                    "sdi_status": null,
                    "sdi_sent_at": null,
                    "payment_terms": "30gg",
                    "notes": "Consulenza giugno 2026",
                    "document_type": "invoice",
                    "document_subtype": "standard",
                    "posting_status": "posted",
                    "created_at": "2026-06-12T14:30:00.000Z",
                    "updated_at": "2026-06-12T14:30:00.000Z",
                    "created_by": "user-uuid",
                    "items": [
                      {
                        "id": "line-uuid",
                        "invoice_id": "550e8400-e29b-41d4-a716-446655440000",
                        "line_number": 1,
                        "line_type": "item",
                        "item_code": "CONS-001",
                        "description": "Consulenza strategica",
                        "quantity": 10,
                        "uom": "H",
                        "unit_price": 150,
                        "discount_percent": 0,
                        "vat_rate": 22,
                        "line_total": 1500,
                        "notes": null,
                        "created_at": "2026-06-12T14:30:00.000Z"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_abc123"
                  }
                }
              }
            }
          },
          "409": {
            "description": "external_id già usato da un'altra fattura (error.existing_id), oppure un DDT citato nelle righe è stato fatturato nel frattempo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore di validazione",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "invoices:write"
            ]
          }
        ]
      }
    },
    "/invoices/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getInvoice",
        "summary": "Ottieni fattura (con righe)",
        "tags": [
          "Invoices"
        ],
        "responses": {
          "200": {
            "description": "Fattura con righe",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/InvoiceResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "550e8400-e29b-41d4-a716-446655440000",
                    "company_id": "company-uuid",
                    "customer_id": "cust-uuid",
                    "invoice_number": "2026/001",
                    "invoice_date": "2026-06-12",
                    "due_date": "2026-07-12",
                    "status": "confirmed",
                    "subtotal": 1500,
                    "vat_amount": 330,
                    "total_amount": 1830,
                    "stamp_duty": null,
                    "payment_status": "unpaid",
                    "paid_amount": 0,
                    "payment_date": null,
                    "payment_method": "bank_transfer",
                    "sdi_status": null,
                    "sdi_sent_at": null,
                    "payment_terms": "30gg",
                    "notes": "Consulenza giugno 2026",
                    "document_type": "invoice",
                    "document_subtype": "standard",
                    "posting_status": "posted",
                    "created_at": "2026-06-12T14:30:00.000Z",
                    "updated_at": "2026-06-12T14:30:00.000Z",
                    "created_by": "user-uuid",
                    "items": [
                      {
                        "id": "line-uuid",
                        "invoice_id": "550e8400-e29b-41d4-a716-446655440000",
                        "line_number": 1,
                        "line_type": "item",
                        "item_code": "CONS-001",
                        "description": "Consulenza strategica",
                        "quantity": 10,
                        "uom": "H",
                        "unit_price": 150,
                        "discount_percent": 0,
                        "vat_rate": 22,
                        "line_total": 1500,
                        "notes": null,
                        "created_at": "2026-06-12T14:30:00.000Z"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_8f3a2b1c"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Fattura non trovata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "invoices:read"
            ]
          }
        ]
      },
      "patch": {
        "operationId": "updateInvoice",
        "summary": "Aggiorna fattura (solo draft)",
        "tags": [
          "Invoices"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateInvoiceRequest"
              },
              "example": {
                "due_date": "2026-08-12",
                "payment_method": "bank_transfer",
                "notes": "Pagamento entro agosto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Fattura aggiornata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/InvoiceResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "uuid",
                    "invoice_number": "2026/042",
                    "invoice_date": "2026-06-12",
                    "due_date": "2026-08-12",
                    "status": "draft",
                    "subtotal": 1500,
                    "vat_amount": 330,
                    "total_amount": 1830,
                    "payment_method": "bank_transfer",
                    "notes": "Pagamento entro agosto",
                    "updated_at": "2026-06-13T10:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_xyz"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Non è in stato draft",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "invoices:write"
            ]
          }
        ]
      },
      "delete": {
        "operationId": "deleteInvoice",
        "summary": "Elimina fattura (solo draft)",
        "tags": [
          "Invoices"
        ],
        "responses": {
          "204": {
            "description": "Eliminata"
          },
          "404": {
            "description": "Non trovata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Non è in stato draft",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "invoices:delete"
            ]
          }
        ]
      }
    },
    "/invoices/{id}/issue": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "issueInvoice",
        "summary": "Emetti fattura (draft → confirmed)",
        "tags": [
          "Invoices"
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Fattura confermata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/InvoiceResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "uuid",
                    "invoice_number": "2026/042",
                    "invoice_date": "2026-06-12",
                    "status": "confirmed",
                    "subtotal": 1500,
                    "vat_amount": 330,
                    "total_amount": 1830,
                    "sdi_status": null,
                    "payment_status": "unpaid",
                    "updated_at": "2026-06-12T15:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_issue1"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Non è in stato draft",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "invoices:write"
            ]
          }
        ]
      }
    },
    "/invoices/{id}/pdf": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getInvoicePdf",
        "summary": "PDF della fattura (copia di cortesia)",
        "tags": [
          "Invoices"
        ],
        "responses": {
          "200": {
            "description": "Il PDF, lo stesso dell'anteprima in esse24",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "404": {
            "description": "Non trovata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "invoices:read"
            ]
          }
        ]
      }
    },
    "/customers": {
      "get": {
        "operationId": "listCustomers",
        "summary": "Elenca clienti",
        "tags": [
          "Customers"
        ],
        "parameters": [
          {
            "name": "search",
            "in": "query",
            "description": "Corrispondenza parziale, senza maiuscole, su name, vat_number, code e tax_code. Per cercare per codice, verificare il code esatto sui risultati.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "blocked",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista clienti",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/CustomerResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "customers:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createCustomer",
        "summary": "Crea cliente",
        "tags": [
          "Customers"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateCustomerRequest"
              },
              "example": {
                "name": "Acme Srl",
                "code": "CLI-001",
                "vat_number": "IT12345678901",
                "tax_code": "12345678901",
                "email": "admin@acme.it",
                "phone": "+39 02 12345678",
                "pec": "acme@pec.it",
                "sdi_code": "ABC1234",
                "billing_address": {
                  "street": "Via Roma 1",
                  "city": "Milano",
                  "province": "MI",
                  "postal_code": "20100",
                  "country": "IT"
                },
                "person_type": "legal",
                "legal_form": "SRL",
                "fiscal_regime": "RF01",
                "payment_terms": "30gg",
                "payment_method": "bank_transfer",
                "split_payment": false,
                "category": "A",
                "discount_percent": 5
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Cliente creato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CustomerResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "cust-new-uuid",
                    "company_id": "company-uuid",
                    "code": "CLI-001",
                    "name": "Acme Srl",
                    "vat_number": "IT12345678901",
                    "tax_code": "12345678901",
                    "email": "admin@acme.it",
                    "pec": "acme@pec.it",
                    "sdi_code": "ABC1234",
                    "payment_terms": "30gg",
                    "payment_method": "bank_transfer",
                    "blocked": false,
                    "customer_status": "active",
                    "split_payment": false,
                    "stamp_duty": false,
                    "blocco_fido": false,
                    "marketing_consent": false,
                    "created_at": "2026-06-12T14:30:00.000Z",
                    "updated_at": "2026-06-12T14:30:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_new_cust"
                  }
                }
              }
            }
          },
          "409": {
            "description": "The VAT number (with or without IT) or the tax code already belongs to another customer of the company: re-point to that customer",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore di validazione",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "customers:write"
            ]
          }
        ]
      }
    },
    "/customers/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getCustomer",
        "summary": "Ottieni cliente",
        "tags": [
          "Customers"
        ],
        "responses": {
          "200": {
            "description": "Cliente",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CustomerResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "cust-uuid",
                    "company_id": "company-uuid",
                    "code": "CLI-001",
                    "name": "Acme Srl",
                    "vat_number": "IT12345678901",
                    "tax_code": "12345678901",
                    "email": "admin@acme.it",
                    "phone": "+39 02 12345678",
                    "website": "https://acme.it",
                    "pec": "acme@pec.it",
                    "sdi_code": "ABC1234",
                    "sdi_code_foreign": null,
                    "payment_terms": "30gg",
                    "payment_method": "bank_transfer",
                    "credit_limit": 50000,
                    "blocked": false,
                    "category": "A",
                    "notes": "Cliente premium",
                    "billing_address": {
                      "street": "Via Roma 1",
                      "city": "Milano",
                      "province": "MI",
                      "postal_code": "20100",
                      "country": "IT"
                    },
                    "shipping_address": {
                      "street": "Via Logistica 5",
                      "city": "Sesto San Giovanni",
                      "province": "MI",
                      "postal_code": "20099",
                      "country": "IT"
                    },
                    "person_type": "legal",
                    "legal_form": "SRL",
                    "fiscal_regime": "RF01",
                    "split_payment": false,
                    "stamp_duty": false,
                    "rea_number": "MI-1234567",
                    "ateco_code": "62.01.00",
                    "vat_regime_type": null,
                    "vat_subject_type": null,
                    "vat_exigibility": null,
                    "withholding_tax_rate": null,
                    "withholding_tax_reason": null,
                    "vies_registered": true,
                    "is_vies_required": true,
                    "vies_status": "valid",
                    "vies_checked_at": "2026-06-01T08:00:00.000Z",
                    "default_account_id": null,
                    "default_cost_center_id": null,
                    "default_project_id": null,
                    "customer_status": "active",
                    "commercial_area": "Nord Italia",
                    "discount_percent": 5,
                    "default_price_list_id": "pl-uuid",
                    "default_agent_id": "agent-uuid",
                    "fido_accordato": 50000,
                    "blocco_fido": false,
                    "marketing_consent": true,
                    "privacy_notes": null,
                    "created_at": "2026-01-15T10:00:00.000Z",
                    "updated_at": "2026-06-01T09:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_get_cust"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "customers:read"
            ]
          }
        ]
      },
      "patch": {
        "operationId": "updateCustomer",
        "summary": "Aggiorna cliente",
        "tags": [
          "Customers"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateCustomerRequest"
              },
              "example": {
                "email": "nuovo@acme.it",
                "phone": "+39 02 99999999",
                "billing_address": {
                  "street": "Via Nuova 10",
                  "city": "Milano",
                  "province": "MI",
                  "postal_code": "20121",
                  "country": "IT"
                },
                "payment_terms": "60gg",
                "category": "B",
                "blocked": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cliente aggiornato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CustomerResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "cust-uuid",
                    "email": "nuovo@acme.it",
                    "phone": "+39 02 99999999",
                    "payment_terms": "60gg",
                    "category": "B",
                    "updated_at": "2026-06-13T10:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_upd_cust"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "La nuova P.IVA (con o senza IT) è già di un altro cliente dell'azienda: riagganciare quel cliente invece di duplicarlo. Il controllo scatta solo se la P.IVA cambia.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore di validazione: nessun campo modificabile, oppure un valore non valido (cortesia, codice di rottura, dicitura in fattura, banca d'appoggio)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "customers:write"
            ]
          }
        ]
      },
      "delete": {
        "operationId": "deleteCustomer",
        "summary": "Elimina cliente",
        "tags": [
          "Customers"
        ],
        "responses": {
          "204": {
            "description": "Eliminato"
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "customers:write"
            ]
          }
        ]
      }
    },
    "/suppliers": {
      "get": {
        "operationId": "listSuppliers",
        "summary": "Elenca fornitori",
        "tags": [
          "Suppliers"
        ],
        "parameters": [
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "blocked",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista fornitori",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SupplierResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "suppliers:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createSupplier",
        "summary": "Crea fornitore",
        "tags": [
          "Suppliers"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateSupplierRequest"
              },
              "example": {
                "name": "Fornitore Srl",
                "code": "FORN-001",
                "vat_number": "IT98765432101",
                "tax_code": "98765432101",
                "email": "info@fornitore.it",
                "phone": "+39 02 98765432",
                "pec": "fornitore@pec.it",
                "billing_address": {
                  "street": "Via Industria 22",
                  "city": "Torino",
                  "province": "TO",
                  "postal_code": "10100",
                  "country": "IT"
                },
                "person_type": "legal",
                "legal_form": "SRL",
                "fiscal_regime": "RF01",
                "payment_terms": "60gg",
                "payment_method": "bank_transfer",
                "is_critical": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Fornitore creato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SupplierResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "supp-new-uuid",
                    "company_id": "company-uuid",
                    "code": "FORN-001",
                    "name": "Fornitore Srl",
                    "vat_number": "IT98765432101",
                    "email": "info@fornitore.it",
                    "payment_terms": "60gg",
                    "blocked": false,
                    "is_critical": false,
                    "split_payment": false,
                    "stamp_duty": false,
                    "created_at": "2026-06-12T14:30:00.000Z",
                    "updated_at": "2026-06-12T14:30:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_new_supp"
                  }
                }
              }
            }
          },
          "409": {
            "description": "The code is already used, or the VAT number (with or without IT) already belongs to another supplier of the company: re-point to that supplier",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore di validazione",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "suppliers:write"
            ]
          }
        ]
      }
    },
    "/suppliers/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getSupplier",
        "summary": "Ottieni fornitore",
        "tags": [
          "Suppliers"
        ],
        "responses": {
          "200": {
            "description": "Fornitore",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SupplierResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "supp-uuid",
                    "company_id": "company-uuid",
                    "code": "FORN-001",
                    "name": "Fornitore Srl",
                    "vat_number": "IT98765432101",
                    "tax_code": "98765432101",
                    "email": "info@fornitore.it",
                    "phone": "+39 02 98765432",
                    "website": null,
                    "pec": "fornitore@pec.it",
                    "sdi_code": null,
                    "payment_terms": "60gg",
                    "payment_method": "bank_transfer",
                    "blocked": false,
                    "is_critical": false,
                    "category": null,
                    "notes": null,
                    "billing_address": {
                      "street": "Via Industria 22",
                      "city": "Torino",
                      "province": "TO",
                      "postal_code": "10100",
                      "country": "IT"
                    },
                    "person_type": "legal",
                    "legal_form": "SRL",
                    "fiscal_regime": "RF01",
                    "split_payment": false,
                    "stamp_duty": false,
                    "created_at": "2026-02-01T10:00:00.000Z",
                    "updated_at": "2026-02-01T10:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_get_supp"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "suppliers:read"
            ]
          }
        ]
      },
      "patch": {
        "operationId": "updateSupplier",
        "summary": "Aggiorna fornitore",
        "tags": [
          "Suppliers"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateSupplierRequest"
              },
              "example": {
                "email": "nuovo@fornitore.it",
                "phone": "+39 02 11111111",
                "payment_terms": "30gg",
                "is_critical": true,
                "blocked": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Fornitore aggiornato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SupplierResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "supp-uuid",
                    "email": "nuovo@fornitore.it",
                    "phone": "+39 02 11111111",
                    "payment_terms": "30gg",
                    "is_critical": true,
                    "blocked": false,
                    "updated_at": "2026-06-13T10:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_upd_supp"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "The new VAT number (with or without IT) already belongs to another supplier of the company",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "suppliers:write"
            ]
          }
        ]
      }
    },
    "/suppliers/{id}/item-codes": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "operationId": "syncSupplierItemCodes",
        "summary": "Allinea i codici articolo del fornitore",
        "description": "Sostituisce l'elenco dei codici con cui il fornitore chiama i tuoi articoli (es. dal PIM). L'elenco è COMPLETO: i codici portati da una chiamata precedente e assenti in questa vengono rimossi. I codici imparati da esse24 dalle bolle restano, anche come secondo codice (alias) dello stesso articolo: un articolo può avere più codici, un codice porta a un solo articolo. Un codice che puntava a un altro articolo viene spostato. Codici con articolo sconosciuto o su più articoli non vengono toccati e tornano nell'esito.",
        "tags": [
          "Suppliers"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "codes"
                ],
                "properties": {
                  "codes": {
                    "type": "array",
                    "maxItems": 25000,
                    "items": {
                      "type": "object",
                      "required": [
                        "supplier_code",
                        "item_code"
                      ],
                      "properties": {
                        "supplier_code": {
                          "type": "string",
                          "maxLength": 100,
                          "description": "Il codice del fornitore, come lo stampa su bolle e fatture."
                        },
                        "item_code": {
                          "type": "string",
                          "maxLength": 100,
                          "description": "Il codice dell'articolo in esse24 (items.code)."
                        }
                      }
                    }
                  }
                }
              },
              "example": {
                "codes": [
                  {
                    "supplier_code": "AUACHC480130B8C",
                    "item_code": "VATC4,8X13"
                  },
                  {
                    "supplier_code": "AUACHC480220B8C",
                    "item_code": "VATC4,8X22"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Esito dell'allineamento",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "received": {
                          "type": "integer"
                        },
                        "adopted": {
                          "type": "integer",
                          "description": "Righe già giuste, ora gestite da questa chiamata."
                        },
                        "inserted": {
                          "type": "integer"
                        },
                        "moved": {
                          "type": "integer",
                          "description": "Codici che puntavano a un altro articolo."
                        },
                        "removed": {
                          "type": "integer",
                          "description": "Codici non più presenti nell'elenco."
                        },
                        "managed_total": {
                          "type": "integer"
                        },
                        "unknown_items_count": {
                          "type": "integer"
                        },
                        "unknown_items": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "supplier_code": {
                                "type": "string"
                              },
                              "item_code": {
                                "type": "string"
                              }
                            }
                          }
                        },
                        "ambiguous_count": {
                          "type": "integer"
                        },
                        "ambiguous": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "supplier_code": {
                                "type": "string"
                              },
                              "item_codes": {
                                "type": "array",
                                "items": {
                                  "type": "string"
                                }
                              }
                            }
                          }
                        },
                        "aliases_total": {
                          "type": "integer",
                          "description": "Codici imparati dalle bolle che restano accanto a un codice mandato da qui, sullo stesso articolo."
                        }
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "received": 479,
                    "adopted": 77,
                    "inserted": 401,
                    "moved": 0,
                    "removed": 0,
                    "managed_total": 478,
                    "unknown_items_count": 1,
                    "unknown_items": [
                      {
                        "supplier_code": "FR264A400180NIC",
                        "item_code": "VPFRPZ4,0X 18"
                      }
                    ],
                    "ambiguous_count": 0,
                    "ambiguous": [],
                    "aliases_total": 0
                  },
                  "meta": {
                    "request_id": "req_sync_codes"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Fornitore non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Corpo non valido",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "suppliers:write"
            ]
          }
        ]
      }
    },
    "/banking/accounts": {
      "get": {
        "operationId": "listBankAccounts",
        "summary": "Elenca conti bancari attivi",
        "description": "Restituisce tutti i conti attivi senza paginazione.",
        "tags": [
          "Banking"
        ],
        "responses": {
          "200": {
            "description": "Lista conti",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/BankAccountResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "acc-uuid",
                      "name": "Conto principale BNL",
                      "display_name": "BNL - Conto corrente",
                      "iban": "IT60X054281110100000123456",
                      "bic": "BNLIITRR",
                      "bank_name": "BNL",
                      "account_type": "current",
                      "currency": "EUR",
                      "current_balance": 15430.5,
                      "available_balance": 15430.5,
                      "is_active": true,
                      "last_sync_date": "2026-06-12T08:00:00.000Z",
                      "created_at": "2025-09-01T00:00:00.000Z",
                      "updated_at": "2026-06-12T08:00:00.000Z"
                    }
                  ],
                  "meta": {
                    "request_id": "req_accs",
                    "timestamp": "2026-06-12T14:30:05.123Z"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "banking:read"
            ]
          }
        ]
      }
    },
    "/banking/accounts/{account_id}/movements": {
      "parameters": [
        {
          "name": "account_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "listBankMovements",
        "summary": "Elenca movimenti di un conto",
        "tags": [
          "Banking"
        ],
        "parameters": [
          {
            "name": "date_from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "date_to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "reconciliation_status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "unmatched",
                "matched",
                "excluded"
              ]
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista movimenti",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/BankTransactionResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "tx-uuid",
                      "account_id": "acc-uuid",
                      "transaction_date": "2026-06-10",
                      "value_date": "2026-06-10",
                      "amount": 1830,
                      "currency": "EUR",
                      "description": "Bonifico - Acme Srl",
                      "counterparty_name": "Acme Srl",
                      "counterparty_iban": "IT60X054281110100000123457",
                      "reference": "Fattura 2026/042",
                      "reconciliation_status": "matched",
                      "matched_invoice_id": "invoice-uuid",
                      "transaction_type": "credit",
                      "is_pending": false,
                      "running_balance": 17260.5,
                      "created_at": "2026-06-10T00:00:00.000Z"
                    }
                  ],
                  "meta": {
                    "request_id": "req_movs",
                    "pagination": {
                      "page": 1,
                      "per_page": 50,
                      "total": 142,
                      "total_pages": 3
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Conto non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "banking:read"
            ]
          }
        ]
      }
    },
    "/banking/movements": {
      "post": {
        "operationId": "createBankMovement",
        "summary": "Registra movimento manuale",
        "tags": [
          "Banking"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateBankMovementRequest"
              },
              "example": {
                "account_id": "acc-uuid",
                "transaction_date": "2026-06-12",
                "description": "Pagamento fornitore manuale",
                "amount": -500,
                "counterparty_name": "Fornitore Srl",
                "reference": "Fattura F2026/010",
                "external_id": "erp-mov-2026-06-12-0001"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Movimento creato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/BankTransactionResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "tx-new-uuid",
                    "account_id": "acc-uuid",
                    "transaction_date": "2026-06-12",
                    "amount": -500,
                    "transaction_type": "debit",
                    "reconciliation_status": "unmatched",
                    "is_pending": false,
                    "created_at": "2026-06-12T14:30:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_mov_new",
                    "timestamp": "2026-06-12T14:30:00.123Z"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Conto non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "A movement with this external_id already exists on this account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore di validazione",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "banking:write"
            ]
          }
        ]
      }
    },
    "/items": {
      "get": {
        "operationId": "listItems",
        "summary": "Elenca articoli",
        "tags": [
          "Items"
        ],
        "parameters": [
          {
            "name": "search",
            "in": "query",
            "description": "Cerca su name, code, sku",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "product",
                "service",
                "expense"
              ]
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "is_active",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "is_cataloged",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista articoli",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ItemResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "550e8400-e29b-41d4-a716-446655440000",
                      "company_id": "company-uuid",
                      "code": "ART-001",
                      "name": "Consulenza oraria",
                      "description": "Consulenza tecnica su progetto",
                      "type": "service",
                      "category": "consulting",
                      "sku": null,
                      "barcode": null,
                      "unit_of_measure": "H",
                      "unit_price": 150,
                      "cost_price": 80,
                      "vat_rate": 22,
                      "stock_quantity": null,
                      "min_stock_level": null,
                      "is_active": true,
                      "brand": null,
                      "model": null,
                      "weight": null,
                      "notes": null,
                      "supplier_id": null,
                      "is_cataloged": true,
                      "status": "active",
                      "tags": [
                        "consulting",
                        "tech"
                      ],
                      "vat_nature": null,
                      "is_reverse_charge": false,
                      "is_split_payment": false,
                      "stamp_duty_applicable": false,
                      "reorder_point": null,
                      "lead_time_days": null,
                      "image_url": null,
                      "created_at": "2026-01-10T09:00:00.000Z",
                      "updated_at": "2026-06-01T10:00:00.000Z"
                    }
                  ],
                  "meta": {
                    "request_id": "req_items",
                    "total": 42,
                    "page": 1,
                    "per_page": 20,
                    "total_pages": 3
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "items:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createItem",
        "summary": "Crea articolo",
        "tags": [
          "Items"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateItemRequest"
              },
              "example": {
                "code": "ART-001",
                "name": "Consulenza oraria",
                "description": "Consulenza tecnica su progetto",
                "type": "service",
                "category": "consulting",
                "unit_of_measure": "H",
                "unit_price": 150,
                "cost_price": 80,
                "vat_rate": 22,
                "is_reverse_charge": false,
                "is_split_payment": false,
                "stamp_duty_applicable": false,
                "is_cataloged": true,
                "tags": [
                  "consulting",
                  "tech"
                ],
                "notes": null
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Articolo creato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ItemResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "550e8400-e29b-41d4-a716-446655440001",
                    "company_id": "company-uuid",
                    "code": "ART-001",
                    "name": "Consulenza oraria",
                    "description": "Consulenza tecnica su progetto",
                    "type": "service",
                    "category": "consulting",
                    "sku": null,
                    "barcode": null,
                    "unit_of_measure": "H",
                    "unit_price": 150,
                    "cost_price": 80,
                    "vat_rate": 22,
                    "stock_quantity": null,
                    "min_stock_level": null,
                    "is_active": true,
                    "brand": null,
                    "model": null,
                    "weight": null,
                    "notes": null,
                    "supplier_id": null,
                    "is_cataloged": true,
                    "status": "active",
                    "tags": [
                      "consulting",
                      "tech"
                    ],
                    "vat_nature": null,
                    "is_reverse_charge": false,
                    "is_split_payment": false,
                    "stamp_duty_applicable": false,
                    "reorder_point": null,
                    "lead_time_days": null,
                    "image_url": null,
                    "created_at": "2026-06-12T14:00:00.000Z",
                    "updated_at": "2026-06-12T14:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_create_item"
                  }
                }
              }
            }
          },
          "409": {
            "description": "`code` gia' usato da un altro articolo dell'azienda. Non ritentare.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore di validazione",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "items:write"
            ]
          }
        ]
      }
    },
    "/items/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getItem",
        "summary": "Ottieni articolo",
        "tags": [
          "Items"
        ],
        "responses": {
          "200": {
            "description": "Articolo",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ItemResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "550e8400-e29b-41d4-a716-446655440001",
                    "company_id": "company-uuid",
                    "code": "ART-001",
                    "name": "Consulenza oraria",
                    "description": "Consulenza tecnica su progetto",
                    "type": "service",
                    "category": "consulting",
                    "sku": null,
                    "barcode": null,
                    "unit_of_measure": "H",
                    "unit_price": 150,
                    "cost_price": 80,
                    "vat_rate": 22,
                    "stock_quantity": null,
                    "min_stock_level": null,
                    "is_active": true,
                    "brand": null,
                    "model": null,
                    "weight": null,
                    "notes": null,
                    "supplier_id": null,
                    "is_cataloged": true,
                    "status": "active",
                    "tags": [
                      "consulting",
                      "tech"
                    ],
                    "vat_nature": null,
                    "is_reverse_charge": false,
                    "is_split_payment": false,
                    "stamp_duty_applicable": false,
                    "reorder_point": null,
                    "lead_time_days": null,
                    "image_url": null,
                    "created_at": "2026-01-10T09:00:00.000Z",
                    "updated_at": "2026-06-01T10:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_get_item"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "items:read"
            ]
          }
        ]
      },
      "patch": {
        "operationId": "updateItem",
        "summary": "Aggiorna articolo",
        "tags": [
          "Items"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateItemRequest"
              },
              "example": {
                "unit_price": 175,
                "is_active": true,
                "notes": "Tariffa aggiornata 2026"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Articolo aggiornato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ItemResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "550e8400-e29b-41d4-a716-446655440001",
                    "company_id": "company-uuid",
                    "code": "ART-001",
                    "name": "Consulenza oraria",
                    "description": "Consulenza tecnica su progetto",
                    "type": "service",
                    "category": "consulting",
                    "sku": null,
                    "barcode": null,
                    "unit_of_measure": "H",
                    "unit_price": 175,
                    "cost_price": 80,
                    "vat_rate": 22,
                    "stock_quantity": null,
                    "min_stock_level": null,
                    "is_active": true,
                    "brand": null,
                    "model": null,
                    "weight": null,
                    "notes": "Tariffa aggiornata 2026",
                    "supplier_id": null,
                    "is_cataloged": true,
                    "status": "active",
                    "tags": [
                      "consulting",
                      "tech"
                    ],
                    "vat_nature": null,
                    "is_reverse_charge": false,
                    "is_split_payment": false,
                    "stamp_duty_applicable": false,
                    "reorder_point": null,
                    "lead_time_days": null,
                    "image_url": null,
                    "created_at": "2026-01-10T09:00:00.000Z",
                    "updated_at": "2026-06-12T15:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_update_item"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "`code` gia' usato da un altro articolo dell'azienda. Non ritentare.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "items:write"
            ]
          }
        ]
      },
      "delete": {
        "operationId": "deleteItem",
        "summary": "Elimina articolo",
        "tags": [
          "Items"
        ],
        "responses": {
          "204": {
            "description": "Eliminato"
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "items:write"
            ]
          }
        ]
      }
    },
    "/items/sync": {
      "put": {
        "operationId": "syncItems",
        "summary": "Allinea articoli e prezzi da un catalogo esterno",
        "description": "Solo per le aziende il cui catalogo nasce fuori da esse24 (catalogo esterno); le altre ricevono 409 `CATALOG_NOT_EXTERNAL`. Fino a 1.000 articoli per chiamata, riconosciuti dal `code`: i nuovi si creano (tipo `goods`, `is_active` default `true`), gli esistenti si aggiornano solo nei campi del sistema esterno (`name`, `description`, `unit_of_measure`, `vat_rate`, `unit_price`, `barcode`, `brand`, `lifecycle_status`, `successor_code`, `is_active`) e solo se cambiano. `cost_price` vale solo alla creazione. Un campo assente non si tocca; `description`, `barcode`, `brand`, `lifecycle_status`, `successor_code` presenti ma vuoti o `null` si cancellano. Due voci con lo stesso `code` nel blocco: vince quella con `updated_at` più recente. `prices` scrive un prezzo per listino (chiave = codice listino esse24); i listini sconosciuti si saltano e si riportano in `listini_sconosciuti`. Chiamata ripetibile: lo stesso blocco due volte dà lo stesso risultato.",
        "tags": [
          "Items"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "items"
                ],
                "properties": {
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 1000,
                    "items": {
                      "type": "object",
                      "required": [
                        "code"
                      ],
                      "properties": {
                        "code": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100
                        },
                        "name": {
                          "type": "string",
                          "maxLength": 500,
                          "nullable": true,
                          "description": "Alla creazione, se manca, si usa `description` o `code`."
                        },
                        "description": {
                          "type": "string",
                          "nullable": true
                        },
                        "unit_of_measure": {
                          "type": "string",
                          "nullable": true,
                          "description": "Default `PZ` alla creazione."
                        },
                        "vat_rate": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 100,
                          "nullable": true,
                          "description": "Default 22 alla creazione."
                        },
                        "unit_price": {
                          "type": "number",
                          "minimum": 0,
                          "nullable": true,
                          "description": "Arrotondato a 2 decimali."
                        },
                        "cost_price": {
                          "type": "number",
                          "minimum": 0,
                          "nullable": true,
                          "description": "Usato solo alla creazione."
                        },
                        "barcode": {
                          "type": "string",
                          "nullable": true
                        },
                        "brand": {
                          "type": "string",
                          "nullable": true
                        },
                        "lifecycle_status": {
                          "type": "string",
                          "nullable": true
                        },
                        "successor_code": {
                          "type": "string",
                          "nullable": true
                        },
                        "is_active": {
                          "type": "boolean",
                          "default": true
                        },
                        "updated_at": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true,
                          "description": "Data di modifica nel sistema esterno."
                        },
                        "prices": {
                          "type": "object",
                          "nullable": true,
                          "description": "`{ codice_listino: prezzo }`, prezzi ≥ 0; un valore `null` si ignora.",
                          "additionalProperties": {
                            "type": "number",
                            "minimum": 0,
                            "nullable": true
                          }
                        }
                      }
                    }
                  }
                }
              },
              "example": {
                "items": [
                  {
                    "code": "VT-M8-40",
                    "name": "Viti M8x40 zincate",
                    "description": "Confezione da 100 pezzi",
                    "unit_of_measure": "CF",
                    "vat_rate": 22,
                    "unit_price": 18.15,
                    "cost_price": 9.4,
                    "barcode": "8001234567890",
                    "brand": "Fischer",
                    "is_active": true,
                    "updated_at": "2026-11-08T14:31:00Z",
                    "prices": {
                      "PIM-PRIV": 18.15,
                      "PIM-UTIL": 14
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Esito del blocco",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "ricevuti": {
                          "type": "integer",
                          "description": "Codici distinti nel blocco."
                        },
                        "inseriti": {
                          "type": "integer"
                        },
                        "aggiornati": {
                          "type": "integer"
                        },
                        "invariati": {
                          "type": "integer"
                        },
                        "prezzi_cambiati": {
                          "type": "integer"
                        },
                        "listini_sconosciuti": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "ricevuti": 1000,
                    "inseriti": 12,
                    "aggiornati": 85,
                    "invariati": 903,
                    "prezzi_cambiati": 140,
                    "listini_sconosciuti": []
                  },
                  "meta": {
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Body non JSON",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "VALIDATION_ERROR",
                    "message": "Body must be JSON.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Il catalogo di questa azienda si gestisce in esse24",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "CATALOG_NOT_EXTERNAL",
                    "message": "sync_items_from_source: il catalogo di questa azienda si gestisce in esse24",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          },
          "422": {
            "description": "`items` vuoto, oltre 1.000 voci, o una voce non valida (l'errore porta `field`, es. `items[3]`); oppure un valore rifiutato dal database (vincolo o formato)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "VALIDATION_ERROR",
                    "message": "items[3] 'code' must be a non-empty string (max 100 chars).",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "items:write"
            ]
          }
        ]
      }
    },
    "/pricelists": {
      "get": {
        "operationId": "listPricelists",
        "summary": "Elenca listini",
        "tags": [
          "Pricelists"
        ],
        "parameters": [
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "is_active",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "direction",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "sales",
                "purchases",
                "both"
              ]
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista listini",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PricelistResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "pl-uuid-001",
                      "company_id": "company-uuid",
                      "code": "LIST-VEN-2026",
                      "name": "Listino vendita 2026",
                      "description": "Listino standard per clienti italiani",
                      "price_list_type": "standard",
                      "currency_code": "EUR",
                      "valid_from": "2026-01-01",
                      "valid_to": null,
                      "is_default": true,
                      "is_active": true,
                      "is_gross": false,
                      "direction": "sales",
                      "priority": 100,
                      "discount_chain": null,
                      "notes": null,
                      "created_at": "2026-01-01T00:00:00.000Z",
                      "updated_at": "2026-01-01T00:00:00.000Z"
                    }
                  ],
                  "meta": {
                    "request_id": "req_pricelists",
                    "total": 3,
                    "page": 1,
                    "per_page": 20,
                    "total_pages": 1
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "pricelists:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createPricelist",
        "summary": "Crea listino",
        "tags": [
          "Pricelists"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePricelistRequest"
              },
              "example": {
                "code": "LIST-VEN-2026",
                "name": "Listino vendita 2026",
                "description": "Listino standard per clienti italiani",
                "price_list_type": "standard",
                "currency_code": "EUR",
                "valid_from": "2026-01-01",
                "valid_to": null,
                "is_default": true,
                "is_active": true,
                "is_gross": false,
                "direction": "sales",
                "priority": 100,
                "discount_chain": null,
                "notes": null
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Listino creato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PricelistResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "pl-uuid-001",
                    "company_id": "company-uuid",
                    "code": "LIST-VEN-2026",
                    "name": "Listino vendita 2026",
                    "description": "Listino standard per clienti italiani",
                    "price_list_type": "standard",
                    "currency_code": "EUR",
                    "valid_from": "2026-01-01",
                    "valid_to": null,
                    "is_default": true,
                    "is_active": true,
                    "is_gross": false,
                    "direction": "sales",
                    "priority": 100,
                    "discount_chain": null,
                    "notes": null,
                    "created_at": "2026-06-12T14:00:00.000Z",
                    "updated_at": "2026-06-12T14:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_create_pl"
                  }
                }
              }
            }
          },
          "409": {
            "description": "`code` gia' usato da un altro listino dell'azienda. Non ritentare.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "pricelists:write"
            ]
          }
        ]
      }
    },
    "/pricelists/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getPricelist",
        "summary": "Ottieni listino",
        "tags": [
          "Pricelists"
        ],
        "responses": {
          "200": {
            "description": "Listino",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PricelistResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "pl-uuid-001",
                    "company_id": "company-uuid",
                    "code": "LIST-VEN-2026",
                    "name": "Listino vendita 2026",
                    "description": "Listino standard per clienti italiani",
                    "price_list_type": "standard",
                    "currency_code": "EUR",
                    "valid_from": "2026-01-01",
                    "valid_to": null,
                    "is_default": true,
                    "is_active": true,
                    "is_gross": false,
                    "direction": "sales",
                    "priority": 100,
                    "discount_chain": null,
                    "notes": null,
                    "created_at": "2026-01-01T00:00:00.000Z",
                    "updated_at": "2026-01-01T00:00:00.000Z",
                    "country_codes": null,
                    "min_margin_pct": null,
                    "is_private_default": false,
                    "rule_count": 3
                  },
                  "meta": {
                    "request_id": "req_get_pl"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "pricelists:read"
            ]
          }
        ]
      },
      "patch": {
        "operationId": "updatePricelist",
        "summary": "Aggiorna listino",
        "tags": [
          "Pricelists"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdatePricelistRequest"
              },
              "example": {
                "priority": 50,
                "is_active": false,
                "notes": "Listino sospeso"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Listino aggiornato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PricelistResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "pl-uuid-001",
                    "company_id": "company-uuid",
                    "code": "LIST-VEN-2026",
                    "name": "Listino vendita 2026",
                    "description": "Listino standard per clienti italiani",
                    "price_list_type": "standard",
                    "currency_code": "EUR",
                    "valid_from": "2026-01-01",
                    "valid_to": null,
                    "is_default": false,
                    "is_active": false,
                    "is_gross": false,
                    "direction": "sales",
                    "priority": 50,
                    "discount_chain": null,
                    "notes": "Listino sospeso",
                    "created_at": "2026-01-01T00:00:00.000Z",
                    "updated_at": "2026-06-12T15:00:00.000Z",
                    "country_codes": null,
                    "min_margin_pct": null,
                    "is_private_default": false
                  },
                  "meta": {
                    "request_id": "req_update_pl"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "`code` gia' usato da un altro listino dell'azienda. Non ritentare.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "pricelists:write"
            ]
          }
        ]
      }
    },
    "/agents": {
      "get": {
        "operationId": "listAgents",
        "summary": "Elenca agenti",
        "tags": [
          "Agents"
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista agenti",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AgentResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "agent-uuid-001",
                      "company_id": "company-uuid",
                      "code": "AG-001",
                      "name": "Mario Rossi",
                      "email": "mario.rossi@esempio.it",
                      "phone": "+39 02 1234567",
                      "fiscal_code": "RSSMRA80A01H501Z",
                      "vat_number": null,
                      "default_commission_rate": 5,
                      "default_commission_base": "net",
                      "is_active": true,
                      "notes": null,
                      "created_at": "2026-01-15T10:00:00.000Z",
                      "updated_at": "2026-01-15T10:00:00.000Z"
                    }
                  ],
                  "meta": {
                    "request_id": "req_agents",
                    "total": 4,
                    "page": 1,
                    "per_page": 20,
                    "total_pages": 1
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "agents:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createAgent",
        "summary": "Crea agente",
        "tags": [
          "Agents"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAgentRequest"
              },
              "example": {
                "code": "AG-001",
                "name": "Mario Rossi",
                "email": "mario.rossi@esempio.it",
                "phone": "+39 02 1234567",
                "fiscal_code": "RSSMRA80A01H501Z",
                "vat_number": null,
                "default_commission_rate": 5,
                "default_commission_base": "net",
                "is_active": true,
                "notes": null
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Agente creato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/AgentResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "agent-uuid-001",
                    "company_id": "company-uuid",
                    "code": "AG-001",
                    "name": "Mario Rossi",
                    "email": "mario.rossi@esempio.it",
                    "phone": "+39 02 1234567",
                    "fiscal_code": "RSSMRA80A01H501Z",
                    "vat_number": null,
                    "default_commission_rate": 5,
                    "default_commission_base": "net",
                    "is_active": true,
                    "notes": null,
                    "created_at": "2026-06-12T14:00:00.000Z",
                    "updated_at": "2026-06-12T14:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_create_agent"
                  }
                }
              }
            }
          },
          "422": {
            "description": "Errore",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "agents:write"
            ]
          }
        ]
      }
    },
    "/agents/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getAgent",
        "summary": "Ottieni agente",
        "tags": [
          "Agents"
        ],
        "responses": {
          "200": {
            "description": "Agente",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/AgentResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "agent-uuid-001",
                    "company_id": "company-uuid",
                    "code": "AG-001",
                    "name": "Mario Rossi",
                    "email": "mario.rossi@esempio.it",
                    "phone": "+39 02 1234567",
                    "fiscal_code": "RSSMRA80A01H501Z",
                    "vat_number": null,
                    "default_commission_rate": 5,
                    "default_commission_base": "net",
                    "is_active": true,
                    "notes": null,
                    "created_at": "2026-01-15T10:00:00.000Z",
                    "updated_at": "2026-01-15T10:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_get_agent"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "agents:read"
            ]
          }
        ]
      },
      "patch": {
        "operationId": "updateAgent",
        "summary": "Aggiorna agente",
        "tags": [
          "Agents"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateAgentRequest"
              },
              "example": {
                "default_commission_rate": 6,
                "is_active": false,
                "notes": "Agente in pausa"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Agente aggiornato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/AgentResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "agent-uuid-001",
                    "company_id": "company-uuid",
                    "code": "AG-001",
                    "name": "Mario Rossi",
                    "email": "mario.rossi@esempio.it",
                    "phone": "+39 02 1234567",
                    "fiscal_code": "RSSMRA80A01H501Z",
                    "vat_number": null,
                    "default_commission_rate": 6,
                    "default_commission_base": "net",
                    "is_active": false,
                    "notes": "Agente in pausa",
                    "created_at": "2026-01-15T10:00:00.000Z",
                    "updated_at": "2026-06-12T15:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_update_agent"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "agents:write"
            ]
          }
        ]
      }
    },
    "/warehouses": {
      "get": {
        "operationId": "listWarehouses",
        "summary": "Elenca magazzini",
        "description": "Restituisce tutti i magazzini senza paginazione.",
        "tags": [
          "Warehouses"
        ],
        "responses": {
          "200": {
            "description": "Lista magazzini",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WarehouseResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "wh-uuid-001",
                      "company_id": "company-uuid",
                      "code": "MAG-01",
                      "name": "Magazzino principale",
                      "address": "Via Roma 1, Milano",
                      "is_active": true,
                      "is_fiscal": true,
                      "valuation_method": "average",
                      "created_at": "2026-01-01T00:00:00.000Z"
                    }
                  ],
                  "meta": {
                    "request_id": "req_warehouses",
                    "total": 2,
                    "page": 1,
                    "per_page": 20,
                    "total_pages": 1
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "warehouses:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createWarehouse",
        "summary": "Crea magazzino",
        "tags": [
          "Warehouses"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWarehouseRequest"
              },
              "example": {
                "code": "MAG-01",
                "name": "Magazzino principale",
                "address": "Via Roma 1, Milano",
                "is_active": true,
                "is_fiscal": true,
                "valuation_method": "average"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Magazzino creato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WarehouseResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "wh-uuid-001",
                    "company_id": "company-uuid",
                    "code": "MAG-01",
                    "name": "Magazzino principale",
                    "address": "Via Roma 1, Milano",
                    "is_active": true,
                    "is_fiscal": true,
                    "valuation_method": "average",
                    "created_at": "2026-06-12T14:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_create_wh"
                  }
                }
              }
            }
          },
          "422": {
            "description": "Errore",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "warehouses:write"
            ]
          }
        ]
      }
    },
    "/warehouses/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getWarehouse",
        "summary": "Ottieni magazzino",
        "tags": [
          "Warehouses"
        ],
        "responses": {
          "200": {
            "description": "Magazzino",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WarehouseResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "wh-uuid-001",
                    "company_id": "company-uuid",
                    "code": "MAG-01",
                    "name": "Magazzino principale",
                    "address": "Via Roma 1, Milano",
                    "is_active": true,
                    "is_fiscal": true,
                    "valuation_method": "average",
                    "created_at": "2026-01-01T00:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_get_wh"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "warehouses:read"
            ]
          }
        ]
      },
      "patch": {
        "operationId": "updateWarehouse",
        "summary": "Aggiorna magazzino",
        "tags": [
          "Warehouses"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateWarehouseRequest"
              },
              "example": {
                "name": "Magazzino Nord",
                "is_active": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Magazzino aggiornato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WarehouseResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "wh-uuid-001",
                    "company_id": "company-uuid",
                    "code": "MAG-01",
                    "name": "Magazzino Nord",
                    "address": "Via Roma 1, Milano",
                    "is_active": false,
                    "is_fiscal": true,
                    "valuation_method": "average",
                    "created_at": "2026-01-01T00:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_update_wh"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "warehouses:write"
            ]
          }
        ]
      }
    },
    "/chart-of-accounts": {
      "get": {
        "operationId": "listChartOfAccounts",
        "summary": "Elenca piano dei conti",
        "tags": [
          "Chart Of Accounts"
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista conti",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ChartOfAccountResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "coa-uuid-001",
                      "code": "1101",
                      "name": "Cassa",
                      "nature": "asset",
                      "account_type": "current",
                      "level": 2,
                      "parent_code": "110",
                      "full_path": "Attività / Cassa",
                      "allow_direct_posting": true,
                      "is_active": true,
                      "is_locked": false,
                      "opening_balance": 0,
                      "debit_movements": 45000,
                      "credit_movements": 42000,
                      "closing_balance": 3000,
                      "movements_count": 38
                    }
                  ],
                  "meta": {
                    "request_id": "req_coa",
                    "total": 120,
                    "page": 1,
                    "per_page": 100,
                    "total_pages": 2
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "accounting:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createChartOfAccount",
        "summary": "Crea voce piano dei conti",
        "tags": [
          "Chart Of Accounts"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateChartOfAccountRequest"
              },
              "example": {
                "code": "1101",
                "name": "Cassa",
                "nature": "asset",
                "account_type": "current",
                "level": 2,
                "parent_id": "coa-parent-uuid",
                "allow_direct_posting": true
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Conto creato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ChartOfAccountResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "coa-uuid-001",
                    "code": "1101",
                    "name": "Cassa",
                    "nature": "asset",
                    "full_path": "Attività / Cassa",
                    "is_active": true,
                    "is_locked": false
                  },
                  "meta": {
                    "request_id": "req_create_coa"
                  }
                }
              }
            }
          },
          "422": {
            "description": "Errore",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "accounting:write"
            ]
          }
        ]
      }
    },
    "/chart-of-accounts/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getChartOfAccount",
        "summary": "Ottieni voce piano dei conti",
        "tags": [
          "Chart Of Accounts"
        ],
        "responses": {
          "200": {
            "description": "Conto",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ChartOfAccountResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "coa-uuid-001",
                    "code": "1101",
                    "name": "Cassa",
                    "nature": "asset",
                    "account_type": "current",
                    "level": 2,
                    "parent_id": "coa-parent-uuid",
                    "parent_code": "110",
                    "full_path": "Attività / Cassa",
                    "allow_direct_posting": true,
                    "vat_managed": false,
                    "is_active": true,
                    "is_locked": false,
                    "opening_balance": 0,
                    "debit_movements": 45000,
                    "credit_movements": 42000,
                    "closing_balance": 3000,
                    "movements_count": 38,
                    "created_at": "2025-01-01T00:00:00.000Z",
                    "updated_at": "2026-06-12T08:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_get_coa"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "accounting:read"
            ]
          }
        ]
      },
      "patch": {
        "operationId": "updateChartOfAccount",
        "summary": "Aggiorna voce piano dei conti (bloccato se is_locked=true)",
        "tags": [
          "Chart Of Accounts"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateChartOfAccountRequest"
              },
              "example": {
                "allow_direct_posting": false,
                "notes": "Solo movimenti automatici"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Conto aggiornato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ChartOfAccountResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "coa-uuid-001",
                    "allow_direct_posting": false
                  },
                  "meta": {
                    "request_id": "req_update_coa"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Conto bloccato (is_locked=true)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "accounting:write"
            ]
          }
        ]
      }
    },
    "/journal/entries": {
      "get": {
        "operationId": "listJournalEntries",
        "summary": "Elenca scritture contabili",
        "tags": [
          "Journal"
        ],
        "parameters": [
          {
            "name": "date_from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "date_to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "to_consolidate",
                "consolidated",
                "locked"
              ]
            }
          },
          {
            "name": "source_type",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista scritture",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/JournalEntryResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "je-uuid-001",
                      "entry_number": "2026/0042",
                      "registration_date": "2026-06-12",
                      "competency_date": "2026-06-12",
                      "description": "Fattura cliente Acme Srl n. 2026/001",
                      "total_debit": 1830,
                      "total_credit": 1830,
                      "status": "consolidated",
                      "is_balanced": true
                    }
                  ],
                  "meta": {
                    "request_id": "req_entries",
                    "total": 312,
                    "page": 1,
                    "per_page": 50,
                    "total_pages": 7
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "accounting:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createJournalEntry",
        "summary": "Crea scrittura contabile",
        "tags": [
          "Journal"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateJournalEntryRequest"
              },
              "example": {
                "registration_date": "2026-06-12",
                "description": "Fattura cliente Acme Srl n. 2026/001",
                "document_number": "2026/001",
                "document_type": "sales_invoice",
                "lines": [
                  {
                    "account_id": "coa-crediti-uuid",
                    "debit_amount": 1830,
                    "credit_amount": 0,
                    "description": "Crediti vs clienti"
                  },
                  {
                    "account_id": "coa-ricavi-uuid",
                    "debit_amount": 0,
                    "credit_amount": 1500,
                    "description": "Ricavi prestazioni"
                  },
                  {
                    "account_id": "coa-iva-uuid",
                    "debit_amount": 0,
                    "credit_amount": 330,
                    "description": "IVA a debito 22%"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Scrittura creata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/JournalEntryResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "je-uuid-new",
                    "entry_number": "2026/0043",
                    "registration_date": "2026-06-12",
                    "total_debit": 1830,
                    "total_credit": 1830,
                    "status": "consolidated",
                    "is_balanced": true,
                    "lines": [
                      {
                        "id": "line-1",
                        "account_code": "1301",
                        "account_name": "Crediti vs clienti",
                        "debit_amount": 1830,
                        "credit_amount": 0
                      },
                      {
                        "id": "line-2",
                        "account_code": "4001",
                        "account_name": "Ricavi prestazioni",
                        "debit_amount": 0,
                        "credit_amount": 1500
                      },
                      {
                        "id": "line-3",
                        "account_code": "2601",
                        "account_name": "IVA a debito",
                        "debit_amount": 0,
                        "credit_amount": 330
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_create_entry"
                  }
                }
              }
            }
          },
          "409": {
            "description": "A request with the same Idempotency-Key is still being processed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore (es. dare ≠ avere) — also returned as IDEMPOTENCY_KEY_REQUIRED when the Idempotency-Key header is missing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "accounting:write"
            ]
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKeyRequired"
          }
        ]
      }
    },
    "/journal/entries/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getJournalEntry",
        "summary": "Ottieni scrittura contabile (con righe)",
        "tags": [
          "Journal"
        ],
        "responses": {
          "200": {
            "description": "Scrittura con righe",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/JournalEntryResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "je-uuid-001",
                    "entry_number": "2026/0042",
                    "registration_date": "2026-06-12",
                    "competency_date": "2026-06-12",
                    "description": "Fattura cliente",
                    "total_debit": 1830,
                    "total_credit": 1830,
                    "status": "consolidated",
                    "is_balanced": true,
                    "lines": [
                      {
                        "line_number": 1,
                        "account_id": "uuid",
                        "account_code": "1301",
                        "account_name": "Crediti vs clienti",
                        "debit_amount": 1830,
                        "credit_amount": 0
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_get_entry"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "accounting:read"
            ]
          }
        ]
      }
    },
    "/receivables": {
      "get": {
        "operationId": "listReceivables",
        "summary": "Scadenzario attivo (crediti verso clienti)",
        "tags": [
          "Receivables"
        ],
        "parameters": [
          {
            "name": "overdue_only",
            "in": "query",
            "description": "true restituisce solo le rate ancora aperte con due_date precedente a oggi.",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "partial",
                "paid",
                "overdue",
                "written_off"
              ]
            }
          },
          {
            "name": "customer_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Liste rate scadenzario attivo",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ReceivableInstallmentResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "inst-uuid-001",
                      "installment_number": 1,
                      "due_date": "2026-07-12",
                      "due_amount": 1830,
                      "applied_amount": 0,
                      "write_off_amount": 0,
                      "remaining_amount": 1830,
                      "status": "open",
                      "type": "receivable",
                      "sales_invoice": {
                        "id": "inv-uuid",
                        "invoice_number": "2026/001",
                        "total_amount": 1830,
                        "status": "issued",
                        "customer": {
                          "id": "cust-uuid",
                          "name": "Acme Srl",
                          "vat_number": "IT12345678901"
                        }
                      }
                    }
                  ],
                  "meta": {
                    "request_id": "req_recv",
                    "total": 14,
                    "page": 1,
                    "per_page": 50,
                    "total_pages": 1
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "receivables:read"
            ]
          }
        ],
        "description": "Una riga per RATA, non per fattura. Non esiste un filtro per intervallo di date: per lo scaduto usare overdue_only."
      }
    },
    "/payables": {
      "get": {
        "operationId": "listPayables",
        "summary": "Scadenzario passivo (debiti verso fornitori)",
        "tags": [
          "Receivables"
        ],
        "parameters": [
          {
            "name": "overdue_only",
            "in": "query",
            "description": "true restituisce solo le rate ancora aperte con due_date precedente a oggi.",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "partial",
                "paid",
                "overdue",
                "written_off"
              ]
            }
          },
          {
            "name": "supplier_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Liste rate scadenzario passivo",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ReceivableInstallmentResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "inst-uuid-002",
                      "installment_number": 1,
                      "due_date": "2026-07-30",
                      "due_amount": 605,
                      "applied_amount": 0,
                      "write_off_amount": 0,
                      "remaining_amount": 605,
                      "status": "open",
                      "type": "payable",
                      "purchase_invoice": {
                        "id": "pinv-uuid",
                        "invoice_number": "FT-2026-088",
                        "total_amount": 605,
                        "status": "issued",
                        "supplier": {
                          "id": "supp-uuid",
                          "name": "Fornitore Srl",
                          "vat_number": "IT98765432109"
                        }
                      }
                    }
                  ],
                  "meta": {
                    "request_id": "req_payab",
                    "total": 8,
                    "page": 1,
                    "per_page": 50,
                    "total_pages": 1
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "receivables:read"
            ]
          }
        ],
        "description": "Una riga per RATA, non per fattura. Non esiste un filtro per intervallo di date: per lo scaduto usare overdue_only."
      }
    },
    "/trial-balance": {
      "get": {
        "operationId": "getTrialBalance",
        "summary": "Bilancio di verifica",
        "tags": [
          "Trial Balance"
        ],
        "parameters": [
          {
            "name": "include_zero_balances",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          },
          {
            "name": "nature",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "asset",
                "liability",
                "equity",
                "revenue",
                "expense"
              ]
            }
          },
          {
            "name": "level",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "allow_direct_posting",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Bilancio di verifica",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/TrialBalanceResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "coa-uuid-001",
                      "code": "1101",
                      "name": "Cassa",
                      "nature": "asset",
                      "account_type": "current",
                      "level": 2,
                      "opening_balance": 0,
                      "debit_movements": 45000,
                      "credit_movements": 42000,
                      "closing_balance": 3000,
                      "movements_count": 38
                    }
                  ],
                  "meta": {
                    "request_id": "req_tb",
                    "account_count": 48,
                    "total_debit_movements": 312500,
                    "total_credit_movements": 312500,
                    "is_balanced": true,
                    "note": "Balances reflect all-time movements stored in chart_of_accounts."
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "accounting:read"
            ]
          }
        ],
        "description": "I saldi comprendono TUTTI i movimenti registrati, non un periodo: non esiste un filtro per date. La risposta lo dichiara nel campo note. Per il bilancio di un esercizio o di un trimestre servono le scritture di /journal/entries, dove date_from e date_to funzionano."
      }
    },
    "/orders": {
      "get": {
        "operationId": "listOrders",
        "summary": "Elenca ordini di vendita",
        "tags": [
          "Orders"
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "customer_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "date_from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "date_to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "source",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "source_external_id",
            "in": "query",
            "description": "Match esatto sulla chiave esterna. Con 'source' forma l'indice di idempotenza dell'ordine.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "order_number",
            "in": "query",
            "description": "Match esatto sul numero documento. E' la chiave per ripescare l'ordine dopo un timeout, quando non si sa se il POST e' andato a buon fine.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "description": "Cerca su order_number, notes (ilike, non esatto: non usare come chiave di recupero)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista ordini (senza items)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SalesOrderResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "ord-uuid-001",
                      "company_id": "company-uuid",
                      "customer_id": "cust-uuid",
                      "order_number": "OV-2026-0042",
                      "order_date": "2026-06-12",
                      "delivery_date": "2026-06-20",
                      "status": "confirmed",
                      "subtotal": 1500,
                      "vat_amount": 330,
                      "total_amount": 1830,
                      "payment_terms": "30gg",
                      "delivery_terms": "EXW",
                      "notes": null,
                      "internal_notes": null,
                      "fulfillment_progress": 0,
                      "quote_id": null,
                      "payment_method": "bank_transfer",
                      "billing_trigger": "delivery",
                      "advance_percentage": null,
                      "source": "api",
                      "source_external_id": "WOO-12345",
                      "discount_footer_pct": null,
                      "discount_footer_amount": null,
                      "cancellation_reason": null,
                      "cancelled_at": null,
                      "created_by": "user-uuid",
                      "created_at": "2026-06-12T09:00:00.000Z",
                      "updated_at": "2026-06-12T09:00:00.000Z"
                    }
                  ],
                  "meta": {
                    "request_id": "req_orders",
                    "total": 87,
                    "page": 1,
                    "per_page": 50,
                    "total_pages": 2
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "orders:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createOrder",
        "summary": "Crea ordine di vendita",
        "description": "L'ordine nasce sempre in 'draft': un 'status' nel body viene ignorato. 'order_number' e' obbligatorio (nessun sezionale server-side per le vendite). Il 'source' scelto qui e' definitivo (non e' patchabile) ed entra nell'indice di idempotenza; Il canale 'sales-order.*' e' spento dal 09-11-2026: ogni scrittura esce come orders.changed nel registro, qualunque sia 'source'.",
        "tags": [
          "Orders"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateOrderRequest"
              },
              "example": {
                "customer_id": "cust-uuid",
                "order_date": "2026-06-12",
                "delivery_date": "2026-06-20",
                "payment_terms": "30gg",
                "delivery_terms": "EXW",
                "payment_method": "bank_transfer",
                "billing_trigger": "delivery",
                "notes": null,
                "internal_notes": "Verificare disponibilità a magazzino",
                "source_external_id": "WOO-12345",
                "discount_footer_pct": null,
                "discount_footer_amount": null,
                "items": [
                  {
                    "line_type": "item",
                    "item_code": "NB-PRO-15",
                    "description": "Notebook Pro 15",
                    "quantity": 2,
                    "uom": "PZ",
                    "unit_price": 750,
                    "discount_percent": 0,
                    "vat_rate": 22,
                    "notes": null
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Ordine creato (con items)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SalesOrderResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "ord-uuid-001",
                    "company_id": "company-uuid",
                    "customer_id": "cust-uuid",
                    "order_number": "OV-2026-0042",
                    "order_date": "2026-06-12",
                    "delivery_date": "2026-06-20",
                    "status": "draft",
                    "subtotal": 1500,
                    "vat_amount": 330,
                    "total_amount": 1830,
                    "payment_terms": "30gg",
                    "delivery_terms": "EXW",
                    "notes": null,
                    "internal_notes": "Verificare disponibilità a magazzino",
                    "fulfillment_progress": 0,
                    "quote_id": null,
                    "payment_method": "bank_transfer",
                    "billing_trigger": "delivery",
                    "advance_percentage": null,
                    "source": "api",
                    "source_external_id": "WOO-12345",
                    "discount_footer_pct": null,
                    "discount_footer_amount": null,
                    "cancellation_reason": null,
                    "cancelled_at": null,
                    "created_by": "user-uuid",
                    "created_at": "2026-06-12T14:00:00.000Z",
                    "updated_at": "2026-06-12T14:00:00.000Z",
                    "items": [
                      {
                        "id": "item-uuid-001",
                        "order_id": "ord-uuid-001",
                        "line_number": 1,
                        "line_type": "item",
                        "item_code": "NB-PRO-15",
                        "description": "Notebook Pro 15",
                        "quantity": 2,
                        "quantity_fulfilled": 0,
                        "uom": "PZ",
                        "unit_price": 750,
                        "discount_percent": 0,
                        "vat_rate": 22,
                        "line_total": 1500,
                        "notes": null,
                        "created_at": "2026-06-12T14:00:00.000Z"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_create_ord"
                  }
                }
              }
            }
          },
          "409": {
            "description": "'order_number' o 'source_external_id' gia' esistenti per questa azienda: l'ordine c'e' gia'. Recuperarlo con GET /orders?order_number=... (o ?source_external_id=...) invece di ritentare la creazione",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore di validazione (customer_id o order_number mancanti, customer_id inesistente, nessuna riga con quantity > 0, sconto di testata fuori range, delivery_address con chiavi legacy)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "orders:write"
            ]
          }
        ]
      }
    },
    "/orders/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getOrder",
        "summary": "Ottieni ordine di vendita (con items)",
        "tags": [
          "Orders"
        ],
        "responses": {
          "200": {
            "description": "Ordine con righe",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SalesOrderResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "ord-uuid-001",
                    "company_id": "company-uuid",
                    "customer_id": "cust-uuid",
                    "order_number": "OV-2026-0042",
                    "order_date": "2026-06-12",
                    "delivery_date": "2026-06-20",
                    "status": "confirmed",
                    "subtotal": 1500,
                    "vat_amount": 330,
                    "total_amount": 1830,
                    "payment_terms": "30gg",
                    "delivery_terms": "EXW",
                    "notes": null,
                    "internal_notes": "Verificare disponibilità a magazzino",
                    "fulfillment_progress": 0,
                    "quote_id": null,
                    "payment_method": "bank_transfer",
                    "billing_trigger": "delivery",
                    "advance_percentage": null,
                    "source": "api",
                    "source_external_id": "WOO-12345",
                    "discount_footer_pct": null,
                    "discount_footer_amount": null,
                    "cancellation_reason": null,
                    "cancelled_at": null,
                    "created_by": "user-uuid",
                    "created_at": "2026-06-12T09:00:00.000Z",
                    "updated_at": "2026-06-12T09:00:00.000Z",
                    "items": [
                      {
                        "id": "item-uuid-001",
                        "order_id": "ord-uuid-001",
                        "line_number": 1,
                        "line_type": "item",
                        "item_code": "NB-PRO-15",
                        "description": "Notebook Pro 15",
                        "quantity": 2,
                        "quantity_fulfilled": 0,
                        "uom": "PZ",
                        "unit_price": 750,
                        "discount_percent": 0,
                        "vat_rate": 22,
                        "line_total": 1500,
                        "notes": null,
                        "created_at": "2026-06-12T09:00:00.000Z"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_get_ord"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "orders:read"
            ]
          }
        ]
      },
      "patch": {
        "operationId": "updateOrder",
        "summary": "Aggiorna ordine di vendita",
        "description": "Accetta 'items' ed esegue un merge selettivo delle righe con chiave 'item_code' (non un replace): inviare sempre l'intero set di righe. Le righe impegnate non vengono mai cancellate: agganciate a un DDT non annullato (per riga, oppure per testata riconoscendo lo stesso 'item_code'), con quantita' evasa o rifiutata. I totali si ricalcolano quando cambiano le righe o lo sconto di testata. La risposta include 'items'.",
        "tags": [
          "Orders"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateOrderRequest"
              },
              "example": {
                "status": "confirmed",
                "delivery_date": "2026-06-22",
                "notes": "Consegna urgente"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ordine aggiornato (con items)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SalesOrderResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "ord-uuid-001",
                    "company_id": "company-uuid",
                    "customer_id": "cust-uuid",
                    "order_number": "OV-2026-0042",
                    "order_date": "2026-06-12",
                    "delivery_date": "2026-06-22",
                    "status": "confirmed",
                    "subtotal": 1500,
                    "vat_amount": 330,
                    "total_amount": 1830,
                    "payment_terms": "30gg",
                    "delivery_terms": "EXW",
                    "notes": "Consegna urgente",
                    "internal_notes": "Verificare disponibilità a magazzino",
                    "fulfillment_progress": 0,
                    "quote_id": null,
                    "payment_method": "bank_transfer",
                    "billing_trigger": "delivery",
                    "advance_percentage": null,
                    "source": "api",
                    "source_external_id": "WOO-12345",
                    "discount_footer_pct": null,
                    "discount_footer_amount": null,
                    "cancellation_reason": null,
                    "cancelled_at": null,
                    "created_by": "user-uuid",
                    "created_at": "2026-06-12T09:00:00.000Z",
                    "updated_at": "2026-06-12T10:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_upd_ord"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Ordine non modificabile: e' annullato, e' gia' fatturato (direttamente o tramite un DDT), oppure si sta cambiando il cliente su un ordine con DDT emessi",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore di validazione (nessun campo aggiornabile, status fuori whitelist o transizione non valida, riga senza description, quantity < 0, unit_price < 0, customer_id inesistente, delivery_address con chiavi legacy)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "orders:write"
            ]
          }
        ]
      }
    },
    "/quotes": {
      "get": {
        "operationId": "listQuotes",
        "summary": "Elenca preventivi",
        "tags": [
          "Quotes"
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "sent",
                "accepted",
                "rejected",
                "expired"
              ]
            }
          },
          {
            "name": "customer_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "date_from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "date_to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista preventivi (senza items)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/QuoteResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "quote-uuid-001",
                      "customer_id": "cust-uuid",
                      "quote_number": "PRV-2026-0015",
                      "quote_date": "2026-06-12",
                      "valid_until": "2026-07-12",
                      "status": "sent",
                      "subtotal": 2000,
                      "vat_amount": 440,
                      "total_amount": 2440,
                      "probability": 70,
                      "created_at": "2026-06-12T09:00:00.000Z"
                    }
                  ],
                  "meta": {
                    "request_id": "req_quotes",
                    "total": 42,
                    "page": 1,
                    "per_page": 50,
                    "total_pages": 1
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "quotes:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createQuote",
        "summary": "Crea preventivo",
        "tags": [
          "Quotes"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateQuoteRequest"
              },
              "example": {
                "customer_id": "cust-uuid",
                "quote_date": "2026-06-12",
                "valid_until": "2026-07-12",
                "probability": 70,
                "payment_terms": "30gg",
                "items": [
                  {
                    "description": "Consulenza implementazione ERP",
                    "quantity": 10,
                    "uom": "h",
                    "unit_price": 200,
                    "vat_rate": 22
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Preventivo creato (con items)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/QuoteResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "quote-uuid-001",
                    "quote_number": "PRV-2026-0015",
                    "status": "draft",
                    "subtotal": 2000,
                    "vat_amount": 440,
                    "total_amount": 2440,
                    "items": [
                      {
                        "id": "item-uuid",
                        "line_number": 1,
                        "description": "Consulenza implementazione ERP",
                        "quantity": 10,
                        "unit_price": 200,
                        "line_total": 2000
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_create_quote"
                  }
                }
              }
            }
          },
          "409": {
            "description": "A request with the same Idempotency-Key is still being processed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore di validazione — also returned as IDEMPOTENCY_KEY_REQUIRED when the Idempotency-Key header is missing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "quotes:write"
            ]
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKeyRequired"
          }
        ]
      }
    },
    "/quotes/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getQuote",
        "summary": "Ottieni preventivo (con items)",
        "tags": [
          "Quotes"
        ],
        "responses": {
          "200": {
            "description": "Preventivo con righe",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/QuoteResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "quote-uuid-001",
                    "quote_number": "PRV-2026-0015",
                    "status": "sent",
                    "total_amount": 2440,
                    "probability": 70,
                    "order_id": null,
                    "items": [
                      {
                        "id": "item-uuid",
                        "description": "Consulenza",
                        "quantity": 10,
                        "line_total": 2000
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_get_quote"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "quotes:read"
            ]
          }
        ]
      },
      "patch": {
        "operationId": "updateQuote",
        "summary": "Aggiorna preventivo",
        "tags": [
          "Quotes"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateQuoteRequest"
              },
              "example": {
                "status": "accepted",
                "probability": 100
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Preventivo aggiornato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/QuoteResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "quote-uuid-001",
                    "status": "accepted",
                    "probability": 100
                  },
                  "meta": {
                    "request_id": "req_upd_quote"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "quotes:write"
            ]
          }
        ]
      }
    },
    "/purchase-orders": {
      "get": {
        "operationId": "listPurchaseOrders",
        "summary": "Elenca ordini di acquisto",
        "tags": [
          "Purchase Orders"
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "supplier_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "date_from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "date_to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "external_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista OdA (senza items)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PurchaseOrderResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "po-uuid-001",
                      "company_id": "company-uuid",
                      "supplier_id": "supp-uuid",
                      "order_number": "OA-2026-0018",
                      "order_date": "2026-06-12",
                      "expected_delivery_date": "2026-06-25",
                      "expected_invoice_date": null,
                      "status": "confirmed",
                      "subtotal": 800,
                      "vat_amount": 176,
                      "total_amount": 976,
                      "payment_terms": "60gg",
                      "delivery_terms": "DAP",
                      "notes": null,
                      "internal_notes": null,
                      "fulfillment_progress": 0,
                      "payment_method": "bank_transfer",
                      "billing_trigger": "delivery",
                      "advance_percentage": null,
                      "external_id": null,
                      "cancellation_reason": null,
                      "cancelled_at": null,
                      "created_by": "user-uuid",
                      "created_at": "2026-06-12T09:00:00.000Z",
                      "updated_at": "2026-06-12T09:00:00.000Z"
                    }
                  ],
                  "meta": {
                    "request_id": "req_pos",
                    "total": 34,
                    "page": 1,
                    "per_page": 50,
                    "total_pages": 1
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "purchase-orders:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createPurchaseOrder",
        "summary": "Crea ordine di acquisto",
        "tags": [
          "Purchase Orders"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePurchaseOrderRequest"
              },
              "example": {
                "supplier_id": "supp-uuid",
                "order_date": "2026-06-12",
                "expected_delivery_date": "2026-06-25",
                "expected_invoice_date": null,
                "payment_terms": "60gg",
                "delivery_terms": "DAP",
                "payment_method": "bank_transfer",
                "billing_trigger": "delivery",
                "notes": null,
                "internal_notes": null,
                "external_id": null,
                "items": [
                  {
                    "line_type": "item",
                    "item_code": "EL-XL200",
                    "description": "Componente elettronico XL200",
                    "quantity": 100,
                    "uom": "PZ",
                    "unit_price": 8,
                    "discount_percent": 0,
                    "vat_rate": 22,
                    "notes": null
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "OdA creato (con items)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PurchaseOrderResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "po-uuid-001",
                    "company_id": "company-uuid",
                    "supplier_id": "supp-uuid",
                    "order_number": "OA-2026-0018",
                    "order_date": "2026-06-12",
                    "expected_delivery_date": "2026-06-25",
                    "expected_invoice_date": null,
                    "status": "draft",
                    "subtotal": 800,
                    "vat_amount": 176,
                    "total_amount": 976,
                    "payment_terms": "60gg",
                    "delivery_terms": "DAP",
                    "notes": null,
                    "internal_notes": null,
                    "fulfillment_progress": 0,
                    "payment_method": "bank_transfer",
                    "billing_trigger": "delivery",
                    "advance_percentage": null,
                    "external_id": null,
                    "cancellation_reason": null,
                    "cancelled_at": null,
                    "created_by": "user-uuid",
                    "created_at": "2026-06-12T14:00:00.000Z",
                    "updated_at": "2026-06-12T14:00:00.000Z",
                    "items": [
                      {
                        "id": "item-uuid",
                        "order_id": "po-uuid-001",
                        "line_number": 1,
                        "line_type": "item",
                        "item_code": "EL-XL200",
                        "description": "Componente elettronico XL200",
                        "quantity": 100,
                        "quantity_fulfilled": 0,
                        "uom": "PZ",
                        "unit_price": 8,
                        "discount_percent": 0,
                        "vat_rate": 22,
                        "line_total": 800,
                        "notes": null,
                        "created_at": "2026-06-12T14:00:00.000Z"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_create_po"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Esiste già un ordine d'acquisto con questo `external_id`: l'errore porta `existing_id`, `existing_order_number` ed `existing_status`. Aggiornarlo con PATCH /purchase-orders/{id} invece di ritentare il POST.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "CONFLICT",
                    "message": "A purchase order with external_id 'NX-PO-4512' already exists for this company. Use PATCH /v1/purchase-orders/{id} to update it.",
                    "request_id": "7c2e9a41-3b6d-4f80-a1c5-9e2d4b8f6a13",
                    "existing_id": "3f1c2a9e-5b7d-4c11-9a2e-8d6f0b1c2e34",
                    "existing_order_number": "OF-2026/0412",
                    "existing_status": "confirmed"
                  }
                }
              }
            }
          },
          "422": {
            "description": "Errore di validazione",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "purchase-orders:write"
            ]
          }
        ]
      }
    },
    "/purchase-orders/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getPurchaseOrder",
        "summary": "Ottieni ordine di acquisto (con items)",
        "tags": [
          "Purchase Orders"
        ],
        "responses": {
          "200": {
            "description": "OdA con righe",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PurchaseOrderResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "po-uuid-001",
                    "company_id": "company-uuid",
                    "supplier_id": "supp-uuid",
                    "order_number": "OA-2026-0018",
                    "order_date": "2026-06-12",
                    "expected_delivery_date": "2026-06-25",
                    "expected_invoice_date": null,
                    "status": "confirmed",
                    "subtotal": 800,
                    "vat_amount": 176,
                    "total_amount": 976,
                    "payment_terms": "60gg",
                    "delivery_terms": "DAP",
                    "notes": null,
                    "internal_notes": null,
                    "fulfillment_progress": 0,
                    "payment_method": "bank_transfer",
                    "billing_trigger": "delivery",
                    "advance_percentage": null,
                    "external_id": null,
                    "cancellation_reason": null,
                    "cancelled_at": null,
                    "created_by": "user-uuid",
                    "created_at": "2026-06-12T09:00:00.000Z",
                    "updated_at": "2026-06-12T09:00:00.000Z",
                    "items": [
                      {
                        "id": "item-uuid",
                        "order_id": "po-uuid-001",
                        "line_number": 1,
                        "line_type": "item",
                        "item_code": "EL-XL200",
                        "description": "Componente elettronico XL200",
                        "quantity": 100,
                        "quantity_fulfilled": 0,
                        "uom": "PZ",
                        "unit_price": 8,
                        "discount_percent": 0,
                        "vat_rate": 22,
                        "line_total": 800,
                        "notes": null,
                        "created_at": "2026-06-12T09:00:00.000Z"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_get_po"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "purchase-orders:read"
            ]
          }
        ]
      },
      "patch": {
        "operationId": "updatePurchaseOrder",
        "summary": "Aggiorna ordine di acquisto (testata e/o righe)",
        "description": "Aggiorna i campi di testata forniti e, se il body contiene `items`, riallinea le righe.\n\nLe righe NON vengono rimpiazzate in blocco: viene eseguito un **merge selettivo con chiave `item_code`**. Le righe gia' impegnate da una consegna restano agganciate ai loro DDT. Vedi `UpdatePurchaseOrderRequest` per la semantica completa.\n\n`line_number` non e' accettato in input: e' assegnato da esse24 e non e' stabile fra un aggiornamento e l'altro.",
        "tags": [
          "Purchase Orders"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdatePurchaseOrderRequest"
              },
              "example": {
                "status": "confirmed",
                "expected_delivery_date": "2026-06-28",
                "notes": "Consegna posticipata",
                "items": [
                  {
                    "item_code": "EL-XL200",
                    "description": "Componente elettronico XL200",
                    "quantity": 120,
                    "uom": "PZ",
                    "unit_price": 8.1,
                    "discount_percent": 0,
                    "vat_rate": 22
                  },
                  {
                    "item_code": "EL-OLD90",
                    "description": "Componente elettronico OLD90",
                    "quantity": 0,
                    "unit_price": 3,
                    "vat_rate": 22
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OdA aggiornato",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PurchaseOrderResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "po-uuid-001",
                    "company_id": "company-uuid",
                    "supplier_id": "supp-uuid",
                    "order_number": "OA-2026-0018",
                    "order_date": "2026-06-12",
                    "expected_delivery_date": "2026-06-28",
                    "expected_invoice_date": null,
                    "status": "confirmed",
                    "subtotal": 972,
                    "vat_amount": 213.84,
                    "total_amount": 1185.84,
                    "payment_terms": "60gg",
                    "delivery_terms": "DAP",
                    "notes": "Consegna posticipata",
                    "internal_notes": null,
                    "fulfillment_progress": 0,
                    "payment_method": "bank_transfer",
                    "billing_trigger": "delivery",
                    "advance_percentage": null,
                    "external_id": null,
                    "cancellation_reason": null,
                    "cancelled_at": null,
                    "created_by": "user-uuid",
                    "created_at": "2026-06-12T09:00:00.000Z",
                    "updated_at": "2026-06-12T10:00:00.000Z",
                    "items": [
                      {
                        "id": "item-uuid",
                        "order_id": "po-uuid-001",
                        "line_number": 1,
                        "line_type": "item",
                        "item_code": "EL-XL200",
                        "description": "Componente elettronico XL200",
                        "quantity": 120,
                        "quantity_fulfilled": 100,
                        "uom": "PZ",
                        "unit_price": 8.1,
                        "discount_percent": 0,
                        "vat_rate": 22,
                        "line_total": 972,
                        "notes": null,
                        "created_at": "2026-06-12T09:00:00.000Z"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_upd_po"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "OdA non modificabile: un DDT collegato e' gia' fatturato, oppure l'ordine e' cancellato e ha gia' consegne/evasione registrate",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore di validazione (nessun campo aggiornabile, riga senza description, quantity < 0, unit_price < 0, transizione di stato non valida)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "purchase-orders:write"
            ]
          }
        ]
      }
    },
    "/purchase-delivery-notes": {
      "get": {
        "operationId": "listPurchaseDeliveryNotes",
        "summary": "Elenca i DDT d'acquisto",
        "description": "Lista paginata dei DDT d'acquisto dell'azienda, per data di emissione decrescente. Non include le righe. Comprende sia i documenti rispecchiati da questa API (resi a fornitore) sia le bolle d'arrivo registrate in esse24.",
        "tags": [
          "Purchase Delivery Notes"
        ],
        "parameters": [
          {
            "name": "external_id",
            "in": "query",
            "description": "Match esatto sull'id del documento nel sistema mittente: è il modo di ripescare un documento dopo un timeout.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "supplier_id",
            "in": "query",
            "description": "Filtra per fornitore.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Match esatto sullo stato.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "DDT d'acquisto, senza righe",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PurchaseDeliveryNoteResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a8c71-9e4b-4d0a-b6f5-1c8e2d7a9b34",
                      "company_id": "a1b2c3d4-0000-4000-8000-000000000001",
                      "supplier_id": "5e6f7a8b-1c2d-4e3f-9a0b-c1d2e3f4a5b6",
                      "ddt_number": "RF-2026/0142",
                      "issue_date": "2026-11-05",
                      "delivery_date": null,
                      "status": "confirmed",
                      "billing_status": "not_billable",
                      "subtotal": 21,
                      "vat_amount": 4.62,
                      "total_amount": 25.62,
                      "notes": "Reso per filettatura difettosa",
                      "external_id": "PORTALE-RESO-88412",
                      "transport_cause_id": "9d8c7b6a-5f4e-4d3c-8b2a-1f0e9d8c7b6a",
                      "linked_invoice_id": null,
                      "origin_ddt_id": "e4d3c2b1-a0f9-4e8d-9c7b-6a5f4e3d2c1b",
                      "return_kind": "credit",
                      "inventory_posted_at": null,
                      "created_at": "2026-11-05T09:14:22.000Z",
                      "updated_at": "2026-11-05T09:14:22.000Z"
                    }
                  ],
                  "meta": {
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "total": 1,
                    "page": 1,
                    "per_page": 20,
                    "total_pages": 1
                  }
                }
              }
            }
          },
          "422": {
            "description": "supplier_id non è un UUID",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "delivery-notes:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createPurchaseDeliveryNote",
        "summary": "Registra un DDT d'acquisto emesso fuori (reso a fornitore)",
        "description": "Rispecchia in esse24 un DDT d'acquisto emesso da un altro sistema, tipicamente il reso a fornitore emesso dal portale. Il documento nasce `confirmed`, non `received`: il magazzino non si muove. La causale è `reso_a_fornitore` salvo `transport_cause` diverso, e deve essere una causale d'acquisto attiva dell'azienda. Totali calcolati dal server dalle righe. `origin_ddt_id` sconosciuto non blocca: il legame viene semplicemente omesso.",
        "tags": [
          "Purchase Delivery Notes"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "supplier_id",
                  "external_id",
                  "ddt_number",
                  "issue_date",
                  "items"
                ],
                "properties": {
                  "supplier_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Fornitore esse24 (da GET /suppliers)."
                  },
                  "external_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Id del documento nel sistema mittente; unico per azienda, impedisce il doppione su un retry."
                  },
                  "ddt_number": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Numero della serie del sistema emittente."
                  },
                  "issue_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "delivery_date": {
                    "type": "string",
                    "format": "date",
                    "description": "Ignorata se non `YYYY-MM-DD`."
                  },
                  "transport_cause": {
                    "type": "string",
                    "default": "reso_a_fornitore",
                    "description": "Codice di una causale di trasporto d'acquisto attiva."
                  },
                  "notes": {
                    "type": "string"
                  },
                  "supplier_reference": {
                    "type": "string",
                    "description": "Salvato, ma non restituito nelle risposte."
                  },
                  "origin_ddt_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Bolla d'arrivo esse24 da cui la merce esce."
                  },
                  "return_kind": {
                    "type": "string",
                    "enum": [
                      "credit",
                      "replacement",
                      "repair"
                    ]
                  },
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "$ref": "#/components/schemas/PurchaseDeliveryNoteLineInput"
                    }
                  }
                }
              },
              "example": {
                "supplier_id": "5e6f7a8b-1c2d-4e3f-9a0b-c1d2e3f4a5b6",
                "external_id": "PORTALE-RESO-88412",
                "ddt_number": "RF-2026/0142",
                "issue_date": "2026-11-05",
                "notes": "Reso per filettatura difettosa",
                "origin_ddt_id": "e4d3c2b1-a0f9-4e8d-9c7b-6a5f4e3d2c1b",
                "return_kind": "credit",
                "items": [
                  {
                    "item_code": "VT-M8-40",
                    "description": "Viti M8x40 zincate — reso per difetto",
                    "quantity": 50,
                    "uom": "PZ",
                    "unit_price": 0.42,
                    "vat_rate": 22
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "DDT registrato (con righe)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PurchaseDeliveryNoteResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "3f2a8c71-9e4b-4d0a-b6f5-1c8e2d7a9b34",
                    "company_id": "a1b2c3d4-0000-4000-8000-000000000001",
                    "supplier_id": "5e6f7a8b-1c2d-4e3f-9a0b-c1d2e3f4a5b6",
                    "ddt_number": "RF-2026/0142",
                    "issue_date": "2026-11-05",
                    "delivery_date": null,
                    "status": "confirmed",
                    "billing_status": "not_billable",
                    "subtotal": 21,
                    "vat_amount": 4.62,
                    "total_amount": 25.62,
                    "notes": "Reso per filettatura difettosa",
                    "external_id": "PORTALE-RESO-88412",
                    "transport_cause_id": "9d8c7b6a-5f4e-4d3c-8b2a-1f0e9d8c7b6a",
                    "linked_invoice_id": null,
                    "origin_ddt_id": "e4d3c2b1-a0f9-4e8d-9c7b-6a5f4e3d2c1b",
                    "return_kind": "credit",
                    "inventory_posted_at": null,
                    "created_at": "2026-11-05T09:14:22.000Z",
                    "updated_at": "2026-11-05T09:14:22.000Z",
                    "items": [
                      {
                        "id": "7c1e9a52-3b0d-4f6e-8a21-5d9c4b7e2f10",
                        "ddt_id": "3f2a8c71-9e4b-4d0a-b6f5-1c8e2d7a9b34",
                        "line_number": 1,
                        "item_code": "VT-M8-40",
                        "description": "Viti M8x40 zincate — reso per difetto",
                        "quantity": 50,
                        "uom": "PZ",
                        "unit_price": 0.42,
                        "discount_percent": 0,
                        "vat_rate": 22,
                        "line_total": 21,
                        "created_at": "2026-11-05T09:14:22.000Z"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Esiste già un DDT d'acquisto con questo `external_id` (il messaggio riporta id e numero), o altro vincolo di unicità",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "CONFLICT",
                    "message": "A purchase delivery note with external_id 'PORTALE-RESO-88412' already exists (id 3f2a8c71-9e4b-4d0a-b6f5-1c8e2d7a9b34, number RF-2026/0142). Use GET /purchase-delivery-notes?external_id=… to retrieve it.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          },
          "422": {
            "description": "Campo obbligatorio mancante o non valido, fornitore non dell'azienda, causale non attiva, riga non valida",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "VALIDATION_ERROR",
                    "message": "Field 'transport_cause' 'reso_a_fornitore' is not an active purchase transport cause for this company.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "delivery-notes:write"
            ]
          }
        ]
      }
    },
    "/purchase-delivery-notes/{id}": {
      "get": {
        "operationId": "getPurchaseDeliveryNote",
        "summary": "Dettaglio DDT d'acquisto",
        "tags": [
          "Purchase Delivery Notes"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "DDT d'acquisto con le righe",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PurchaseDeliveryNoteResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "3f2a8c71-9e4b-4d0a-b6f5-1c8e2d7a9b34",
                    "company_id": "a1b2c3d4-0000-4000-8000-000000000001",
                    "supplier_id": "5e6f7a8b-1c2d-4e3f-9a0b-c1d2e3f4a5b6",
                    "ddt_number": "RF-2026/0142",
                    "issue_date": "2026-11-05",
                    "delivery_date": null,
                    "status": "confirmed",
                    "billing_status": "not_billable",
                    "subtotal": 21,
                    "vat_amount": 4.62,
                    "total_amount": 25.62,
                    "notes": "Reso per filettatura difettosa",
                    "external_id": "PORTALE-RESO-88412",
                    "transport_cause_id": "9d8c7b6a-5f4e-4d3c-8b2a-1f0e9d8c7b6a",
                    "linked_invoice_id": null,
                    "origin_ddt_id": "e4d3c2b1-a0f9-4e8d-9c7b-6a5f4e3d2c1b",
                    "return_kind": "credit",
                    "inventory_posted_at": null,
                    "created_at": "2026-11-05T09:14:22.000Z",
                    "updated_at": "2026-11-05T09:14:22.000Z",
                    "items": [
                      {
                        "id": "7c1e9a52-3b0d-4f6e-8a21-5d9c4b7e2f10",
                        "ddt_id": "3f2a8c71-9e4b-4d0a-b6f5-1c8e2d7a9b34",
                        "line_number": 1,
                        "item_code": "VT-M8-40",
                        "description": "Viti M8x40 zincate — reso per difetto",
                        "quantity": 50,
                        "uom": "PZ",
                        "unit_price": 0.42,
                        "discount_percent": 0,
                        "vat_rate": 22,
                        "line_total": 21,
                        "created_at": "2026-11-05T09:14:22.000Z"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Id non UUID",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "VALIDATION_ERROR",
                    "message": "Invalid ID format. Must be a valid UUID.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          },
          "404": {
            "description": "DDT inesistente per questa azienda",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "NOT_FOUND",
                    "message": "Purchase delivery note 3f2a8c71-9e4b-4d0a-b6f5-1c8e2d7a9b34 not found.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "delivery-notes:read"
            ]
          }
        ]
      },
      "patch": {
        "operationId": "updatePurchaseDeliveryNote",
        "summary": "Corregge un DDT d'acquisto rispecchiato",
        "description": "Corregge un documento nato da questa API (con `external_id`), ad esempio il reso riaperto in revisione nel portale. Aggiorna solo i campi presenti. Con `items` la sostituzione delle righe è integrale e i totali si ricalcolano. Rifiutato con 409 se il documento non è uno specchio, è annullato, è collegato a una fattura, ha righe abbinate a una nota di credito o a una fattura, o ha ripartizioni di fatturazione. `notes` e `supplier_reference` vuoti o `null` si cancellano. Un `origin_ddt_id` sconosciuto lascia il legame com'era.",
        "tags": [
          "Purchase Delivery Notes"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "minProperties": 1,
                "properties": {
                  "supplier_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "ddt_number": {
                    "type": "string",
                    "minLength": 1
                  },
                  "issue_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "delivery_date": {
                    "type": "string",
                    "format": "date",
                    "nullable": true
                  },
                  "notes": {
                    "type": "string",
                    "nullable": true
                  },
                  "supplier_reference": {
                    "type": "string",
                    "nullable": true
                  },
                  "return_kind": {
                    "type": "string",
                    "enum": [
                      "credit",
                      "replacement",
                      "repair"
                    ]
                  },
                  "origin_ddt_id": {
                    "type": "string",
                    "format": "uuid",
                    "nullable": true
                  },
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "description": "Sostituisce tutte le righe.",
                    "items": {
                      "$ref": "#/components/schemas/PurchaseDeliveryNoteLineInput"
                    }
                  }
                }
              },
              "example": {
                "notes": "Reso ridotto dopo verifica",
                "items": [
                  {
                    "item_code": "VT-M8-40",
                    "description": "Viti M8x40 zincate — reso per difetto",
                    "quantity": 40,
                    "uom": "PZ",
                    "unit_price": 0.42,
                    "vat_rate": 22
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "DDT aggiornato (con righe)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PurchaseDeliveryNoteResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "3f2a8c71-9e4b-4d0a-b6f5-1c8e2d7a9b34",
                    "company_id": "a1b2c3d4-0000-4000-8000-000000000001",
                    "supplier_id": "5e6f7a8b-1c2d-4e3f-9a0b-c1d2e3f4a5b6",
                    "ddt_number": "RF-2026/0142",
                    "issue_date": "2026-11-05",
                    "delivery_date": null,
                    "status": "confirmed",
                    "billing_status": "not_billable",
                    "subtotal": 16.8,
                    "vat_amount": 3.7,
                    "total_amount": 20.5,
                    "notes": "Reso ridotto dopo verifica",
                    "external_id": "PORTALE-RESO-88412",
                    "transport_cause_id": "9d8c7b6a-5f4e-4d3c-8b2a-1f0e9d8c7b6a",
                    "linked_invoice_id": null,
                    "origin_ddt_id": "e4d3c2b1-a0f9-4e8d-9c7b-6a5f4e3d2c1b",
                    "return_kind": "credit",
                    "inventory_posted_at": null,
                    "created_at": "2026-11-05T09:14:22.000Z",
                    "updated_at": "2026-11-06T10:02:45.000Z",
                    "items": [
                      {
                        "id": "8d2f0b63-4c1e-4a7f-9b32-6e0d5c8f3a21",
                        "ddt_id": "3f2a8c71-9e4b-4d0a-b6f5-1c8e2d7a9b34",
                        "line_number": 1,
                        "item_code": "VT-M8-40",
                        "description": "Viti M8x40 zincate — reso per difetto",
                        "quantity": 40,
                        "uom": "PZ",
                        "unit_price": 0.42,
                        "discount_percent": 0,
                        "vat_rate": 22,
                        "line_total": 16.8,
                        "created_at": "2026-11-06T10:02:45.000Z"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Id non UUID",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "VALIDATION_ERROR",
                    "message": "Invalid ID format. Must be a valid UUID.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          },
          "404": {
            "description": "DDT inesistente per questa azienda",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "NOT_FOUND",
                    "message": "Purchase delivery note 3f2a8c71-9e4b-4d0a-b6f5-1c8e2d7a9b34 not found.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Documento non modificabile da qui: non nato da questa API, annullato, già in fattura, con righe abbinate o con ripartizioni di fatturazione",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "CONFLICT",
                    "message": "Purchase delivery note 3f2a8c71-9e4b-4d0a-b6f5-1c8e2d7a9b34 is already linked to an invoice and cannot be modified.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          },
          "422": {
            "description": "Campo non valido o nessun campo aggiornabile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "VALIDATION_ERROR",
                    "message": "No updatable fields provided.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "delivery-notes:write"
            ]
          }
        ]
      }
    },
    "/purchase-delivery-notes/{id}/line-corrections": {
      "post": {
        "operationId": "correctPurchaseDeliveryNoteLine",
        "summary": "Corregge una riga di una bolla d'arrivo",
        "description": "Corregge la quantità di UNA riga di una bolla d'acquisto registrata in esse24, tenendo id, abbinamenti con la fattura e carico di magazzino. La riga si indica con `line_id`; senza (bolle arrivate al portale prima del 16/10/2026) si cerca per `item_code` e `quantity_before`, e deve essercene una sola. Con `factor_wrong: true` è l'unità a essere sbagliata, non la merce: prezzo, carico e fattura si riscalano col rapporto delle quantità e il fattore di conversione del codice fornitore si aggiorna (vale `factor` se mandato). La parte oltre il residuo dell'ordine diventa una riga in più della stessa bolla. Ripetere la stessa correzione risponde `status: \"already\"`. POST e non PATCH perché l'`Idempotency-Key` del gateway la renda sicura da rinviare.",
        "tags": [
          "Purchase Delivery Notes"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "quantity"
                ],
                "properties": {
                  "line_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Id della riga. Se assente servono `item_code` e `quantity_before`."
                  },
                  "item_code": {
                    "type": "string",
                    "description": "Codice della riga (o della riga d'ordine abbinata). Obbligatorio senza `line_id`."
                  },
                  "quantity_before": {
                    "type": "number",
                    "description": "Quantità attuale della riga. Obbligatoria senza `line_id`."
                  },
                  "quantity": {
                    "type": "number",
                    "minimum": 0,
                    "description": "Quantità corretta."
                  },
                  "factor_wrong": {
                    "type": "boolean",
                    "default": false,
                    "description": "`true` = l'unità di misura è sbagliata, non il numero di pezzi. Ignorato quando la quantità va da o a zero."
                  },
                  "factor": {
                    "type": "number",
                    "exclusiveMinimum": 0,
                    "description": "Fattore di conversione scritto da chi corregge; vale solo con `factor_wrong: true`."
                  },
                  "reason": {
                    "type": "string",
                    "description": "Motivo, finisce nelle note della riga."
                  },
                  "author": {
                    "type": "string",
                    "description": "Chi corregge; default `Portale`."
                  }
                }
              },
              "example": {
                "line_id": "7c1e9a52-3b0d-4f6e-8a21-5d9c4b7e2f10",
                "quantity": 1,
                "factor_wrong": true,
                "factor": 0.5,
                "reason": "2 pezzi del fornitore = 1 confezione",
                "author": "Andrea"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Esito della correzione (`status: ok`), o riga già con quella quantità (`status: already`, con solo `line_id` e `quantity`)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string",
                          "enum": [
                            "ok",
                            "already"
                          ]
                        },
                        "line_id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "ddt_number": {
                          "type": "string"
                        },
                        "quantity_before": {
                          "type": "number"
                        },
                        "quantity": {
                          "type": "number"
                        },
                        "unit_changed": {
                          "type": "boolean"
                        },
                        "factor_before": {
                          "type": "number",
                          "nullable": true
                        },
                        "factor_after": {
                          "type": "number",
                          "nullable": true
                        },
                        "factor_written": {
                          "type": "boolean"
                        },
                        "invoice": {
                          "type": "string",
                          "enum": [
                            "nessuna",
                            "allineata",
                            "allocazione_allineata",
                            "allocazione_riscalata"
                          ],
                          "description": "Cosa è successo alla fattura collegata."
                        },
                        "stock": {
                          "type": "string",
                          "description": "Cosa è successo al carico di magazzino, in italiano (es. `nessun carico`, `carico corretto`, `rettifica in uscita di 2`)."
                        },
                        "mappings_updated": {
                          "type": "integer",
                          "description": "Abbinamenti codice fornitore aggiornati o creati."
                        },
                        "over_order": {
                          "type": "number",
                          "description": "Quantità oltre il residuo dell'ordine, finita su una riga in più."
                        }
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "status": "ok",
                    "line_id": "7c1e9a52-3b0d-4f6e-8a21-5d9c4b7e2f10",
                    "ddt_number": "DDA-2026/1505",
                    "quantity_before": 2,
                    "quantity": 1,
                    "unit_changed": true,
                    "factor_before": 1,
                    "factor_after": 0.5,
                    "factor_written": true,
                    "invoice": "nessuna",
                    "stock": "carico riportato all'unità giusta",
                    "mappings_updated": 1,
                    "over_order": 0
                  },
                  "meta": {
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Id non UUID",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "VALIDATION_ERROR",
                    "message": "Invalid ID format. Must be a valid UUID.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Bolla o riga non trovata (`BOLLA_NON_TROVATA`, `RIGA_NON_TROVATA` nel messaggio)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "NOT_FOUND",
                    "message": "RIGA_NON_TROVATA: nella bolla DDA-2026/1505 ci sono 2 righe di VT-M8-40 da 2: va corretta in esse24",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Regola di esse24 che impedisce la correzione: riga già in fattura per un'altra quantità (`IN_FATTURA`), bolla annullata (`BOLLA_ANNULLATA`), oltre l'ordinato su una riga fatturata (`OLTRE_ORDINE_IN_FATTURA`), sovra-ricezione",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "CONFLICT",
                    "message": "IN_FATTURA: la riga è già in fattura FA-2026/0881 per 2 (riga di fattura: 2): si corregge solo per allinearla alla fattura, serve l'amministrazione",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          },
          "422": {
            "description": "`quantity` mancante o negativa, `line_id` non UUID, mancano `item_code`/`quantity_before`, `factor` non positivo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "VALIDATION_ERROR",
                    "message": "Without 'line_id', both 'item_code' and 'quantity_before' are required.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "delivery-notes:write"
            ]
          }
        ]
      }
    },
    "/purchase-invoices": {
      "get": {
        "operationId": "listPurchaseInvoices",
        "summary": "Elenca le fatture d'acquisto",
        "description": "Lista paginata delle fatture e note di credito dei fornitori registrate in esse24, per data fattura decrescente. Solo la testata: nome del fornitore, sede, bolle e righe stanno nel dettaglio. Comprende le bozze (`status: draft`) e le autofatture (`is_autoinvoice: true`).",
        "tags": [
          "Purchase Invoices"
        ],
        "parameters": [
          {
            "name": "supplier_id",
            "in": "query",
            "description": "Filtra per fornitore.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Match esatto sullo stato (`draft`, `received`, `approved`).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "external_id",
            "in": "query",
            "description": "Match esatto sull'id esterno (per le fatture arrivate da SDI: `sdi:<nome file>`).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "date_from",
            "in": "query",
            "description": "Data fattura da (compresa).",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "date_to",
            "in": "query",
            "description": "Data fattura fino a (compresa).",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Fatture d'acquisto, solo testata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PurchaseInvoiceResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "bde646f7-d844-4122-b2d0-66ce35806b15",
                      "supplier_id": "3570cba5-9fa6-4122-b932-da49e14cc3a8",
                      "invoice_number": "029363",
                      "invoice_date": "2026-11-24",
                      "registration_date": null,
                      "received_at": "2026-11-25",
                      "due_date": "2027-03-05",
                      "document_type": "invoice",
                      "document_subtype": "standard",
                      "is_autoinvoice": false,
                      "autoinvoice_td_code": null,
                      "autoinvoice_source_id": null,
                      "status": "received",
                      "posting_status": "posted",
                      "subtotal": 1096.18,
                      "vat_amount": 241.16,
                      "total_amount": 1337.34,
                      "payment_status": "unpaid",
                      "paid_amount": 0,
                      "payment_date": null,
                      "payment_terms": "Bonifico",
                      "currency_code": "EUR",
                      "original_invoice_id": null,
                      "origin": "sdi",
                      "external_id": "sdi:IT02355260981_ic3cH.xml.p7m",
                      "site_id": "3be57f21-7a0e-45d4-92c6-21b88a6e227a",
                      "notes": "Importata da A-Cube SDI · IT02355260981_ic3cH.xml.p7m",
                      "created_at": "2026-11-25T08:11:03.755819+00:00",
                      "updated_at": "2026-11-25T08:59:34.583076+00:00"
                    }
                  ],
                  "meta": {
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "total": 1,
                    "page": 1,
                    "per_page": 20,
                    "total_pages": 1
                  }
                }
              }
            }
          },
          "422": {
            "description": "supplier_id non è un UUID, o date_from/date_to non sono YYYY-MM-DD",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "VALIDATION_ERROR",
                    "message": "Query parameter 'date_from' must be YYYY-MM-DD.",
                    "field": "date_from",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "purchase-invoices:read"
            ]
          }
        ]
      }
    },
    "/purchase-invoices/{id}": {
      "get": {
        "operationId": "getPurchaseInvoice",
        "summary": "Dettaglio fattura d'acquisto",
        "description": "Testata, bolle che la fattura chiude (`delivery_notes`) e righe (`items`). È il `data` degli eventi `purchase-invoices.changed`.",
        "tags": [
          "Purchase Invoices"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Fattura d'acquisto con bolle e righe",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PurchaseInvoiceResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "bde646f7-d844-4122-b2d0-66ce35806b15",
                    "supplier_id": "3570cba5-9fa6-4122-b932-da49e14cc3a8",
                    "supplier_name": "INOX MARE SRL",
                    "supplier_vat": "03155230406",
                    "supplier_code": "80",
                    "invoice_number": "029363",
                    "invoice_date": "2026-11-24",
                    "registration_date": null,
                    "received_at": "2026-11-25",
                    "due_date": "2027-03-05",
                    "document_type": "invoice",
                    "document_subtype": "standard",
                    "is_autoinvoice": false,
                    "autoinvoice_td_code": null,
                    "autoinvoice_source_id": null,
                    "status": "received",
                    "posting_status": "posted",
                    "subtotal": 1096.18,
                    "vat_amount": 241.16,
                    "total_amount": 1337.34,
                    "payment_status": "unpaid",
                    "paid_amount": 0,
                    "payment_date": null,
                    "payment_terms": "Bonifico",
                    "currency_code": "EUR",
                    "original_invoice_id": null,
                    "origin": "sdi",
                    "external_id": "sdi:IT02355260981_ic3cH.xml.p7m",
                    "site_id": "3be57f21-7a0e-45d4-92c6-21b88a6e227a",
                    "site_code": "CERVASCA",
                    "site_external_codes": [
                      "00"
                    ],
                    "notes": "Importata da A-Cube SDI · IT02355260981_ic3cH.xml.p7m",
                    "created_at": "2026-11-25T08:11:03.755819+00:00",
                    "updated_at": "2026-11-25T08:59:34.583076+00:00",
                    "delivery_notes": [
                      {
                        "id": "a58dfda4-6bb1-4bf4-95e1-1ae2709759fe",
                        "number": "DDA-2026/2948",
                        "date": "2026-11-24",
                        "supplier_reference": "029363",
                        "external_id": null,
                        "billed_amount": 1096.18
                      }
                    ],
                    "items": [
                      {
                        "id": "9b426695-6b3b-4b0f-9d69-9278b9eece98",
                        "line_number": 2,
                        "item_code": "57371008002",
                        "description": "VITE TE PF DIN 931-M10X80-A2-70",
                        "quantity": 50,
                        "uom": "N.",
                        "unit_price": 0.1497,
                        "discount_percent": 0,
                        "vat_rate": 22,
                        "line_total": 7.48,
                        "ddt_reference": "029363",
                        "ddt_date": "2026-11-24",
                        "order_reference": null,
                        "order_date": null,
                        "matched_ddt_line_id": "d38870ed-8095-4c10-8405-7399a0599794",
                        "delivery_note_id": "a58dfda4-6bb1-4bf4-95e1-1ae2709759fe",
                        "order_line_id": "5decc6cb-4f82-42d6-8ea9-e5a58b5eeb13",
                        "order_id": "666f65ee-9fe2-4d72-9931-68a205e9fdd6",
                        "order_number": "1081/00",
                        "order_external_id": "PA-2026-001930",
                        "order_line_number": 1,
                        "order_line_item_code": "151100"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Id non UUID",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "VALIDATION_ERROR",
                    "message": "Invalid ID format. Must be a valid UUID.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Fattura inesistente per questa azienda",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "NOT_FOUND",
                    "message": "Purchase invoice bde646f7-d844-4122-b2d0-66ce35806b15 not found.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "purchase-invoices:read"
            ]
          }
        ]
      }
    },
    "/stock-movements": {
      "get": {
        "operationId": "listStockMovements",
        "summary": "Elenca movimenti di magazzino",
        "tags": [
          "Stock Movements"
        ],
        "parameters": [
          {
            "name": "warehouse_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "doc_type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "load",
                "unload",
                "transfer",
                "adjustment"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "confirmed",
                "cancelled"
              ]
            }
          },
          {
            "name": "date_from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "date_to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista movimenti (senza lines)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/StockMovementResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "mov-uuid-001",
                      "company_id": "company-uuid",
                      "warehouse_id": "wh-uuid",
                      "doc_date": "2026-06-12",
                      "doc_number": "ENT-2026-0055",
                      "doc_type": "RECEIPT",
                      "counterparty_name": "Fornitore Srl",
                      "reference": "OA-2026-0018",
                      "notes": null,
                      "total_value": 800,
                      "status": "confirmed",
                      "movement_reason_id": null,
                      "source_doc_type": "purchase_order",
                      "source_doc_id": "po-uuid-001",
                      "source_doc_number": "OA-2026-0018",
                      "created_at": "2026-06-12T10:00:00.000Z",
                      "updated_at": "2026-06-12T10:00:00.000Z"
                    }
                  ],
                  "meta": {
                    "request_id": "req_mov",
                    "total": 120,
                    "page": 1,
                    "per_page": 50,
                    "total_pages": 3
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "stock-movements:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createStockMovement",
        "summary": "Crea movimento di magazzino",
        "tags": [
          "Stock Movements"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateStockMovementRequest"
              },
              "example": {
                "warehouse_id": "wh-uuid",
                "doc_date": "2026-06-12",
                "doc_number": "ENT-2026-0055",
                "doc_type": "RECEIPT",
                "counterparty_name": "Fornitore Srl",
                "reference": "OA-2026-0018",
                "notes": null,
                "movement_reason_id": null,
                "source_doc_type": "purchase_order",
                "source_doc_id": "po-uuid-001",
                "source_doc_number": "OA-2026-0018",
                "lines": [
                  {
                    "item_id": "item-uuid",
                    "item_code": "EL-XL200",
                    "item_name": "Componente elettronico XL200",
                    "qty": 100,
                    "uom": "PZ",
                    "location_name": null,
                    "lot": null,
                    "serial": null,
                    "unit_cost": 8
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Movimento creato (con lines)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/StockMovementResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "mov-uuid-001",
                    "company_id": "company-uuid",
                    "warehouse_id": "wh-uuid",
                    "doc_date": "2026-06-12",
                    "doc_number": "ENT-2026-0055",
                    "doc_type": "RECEIPT",
                    "counterparty_name": "Fornitore Srl",
                    "reference": "OA-2026-0018",
                    "notes": null,
                    "total_value": 800,
                    "status": "draft",
                    "movement_reason_id": null,
                    "source_doc_type": "purchase_order",
                    "source_doc_id": "po-uuid-001",
                    "source_doc_number": "OA-2026-0018",
                    "created_at": "2026-06-12T14:00:00.000Z",
                    "updated_at": "2026-06-12T14:00:00.000Z",
                    "lines": [
                      {
                        "id": "line-uuid",
                        "movement_id": "mov-uuid-001",
                        "item_id": "item-uuid",
                        "item_code": "EL-XL200",
                        "item_name": "Componente elettronico XL200",
                        "qty": 100,
                        "uom": "PZ",
                        "location_name": null,
                        "lot": null,
                        "serial": null,
                        "unit_cost": 8,
                        "total_value": 800,
                        "created_at": "2026-06-12T14:00:00.000Z"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_create_mov"
                  }
                }
              }
            }
          },
          "409": {
            "description": "A request with the same Idempotency-Key is still being processed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore di validazione — also returned as IDEMPOTENCY_KEY_REQUIRED when the Idempotency-Key header is missing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "stock-movements:write"
            ]
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKeyRequired"
          }
        ]
      }
    },
    "/stock-movements/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getStockMovement",
        "summary": "Ottieni movimento di magazzino (con lines)",
        "tags": [
          "Stock Movements"
        ],
        "responses": {
          "200": {
            "description": "Movimento con righe",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/StockMovementResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "mov-uuid-001",
                    "company_id": "company-uuid",
                    "warehouse_id": "wh-uuid",
                    "doc_date": "2026-06-12",
                    "doc_number": "ENT-2026-0055",
                    "doc_type": "RECEIPT",
                    "counterparty_name": "Fornitore Srl",
                    "reference": "OA-2026-0018",
                    "notes": null,
                    "total_value": 800,
                    "status": "confirmed",
                    "movement_reason_id": null,
                    "source_doc_type": "purchase_order",
                    "source_doc_id": "po-uuid-001",
                    "source_doc_number": "OA-2026-0018",
                    "created_at": "2026-06-12T10:00:00.000Z",
                    "updated_at": "2026-06-12T10:00:00.000Z",
                    "lines": [
                      {
                        "id": "line-uuid",
                        "movement_id": "mov-uuid-001",
                        "item_id": "item-uuid",
                        "item_code": "EL-XL200",
                        "item_name": "Componente elettronico XL200",
                        "qty": 100,
                        "uom": "PZ",
                        "location_name": null,
                        "lot": null,
                        "serial": null,
                        "unit_cost": 8,
                        "total_value": 800,
                        "created_at": "2026-06-12T10:00:00.000Z"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_get_mov"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "stock-movements:read"
            ]
          }
        ]
      }
    },
    "/company": {
      "get": {
        "operationId": "getCompany",
        "summary": "Ottieni dati aziendali",
        "description": "Restituisce i dati dell'azienda associata all'API key. Sola lettura.",
        "tags": [
          "Company"
        ],
        "responses": {
          "200": {
            "description": "Dati aziendali",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CompanyResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "company-uuid",
                    "name": "La Mia Azienda Srl",
                    "vat_number": "IT12345678901",
                    "fiscal_code": "12345678901",
                    "country": "IT",
                    "address": {
                      "street": "Via Verdi 10",
                      "city": "Roma",
                      "province": "RM",
                      "postal_code": "00100",
                      "country": "IT"
                    },
                    "created_at": "2025-09-01T00:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_company",
                    "timestamp": "2026-06-12T14:30:05.123Z"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "company:read"
            ]
          }
        ]
      }
    },
    "/webhooks/subscriptions": {
      "get": {
        "operationId": "listWebhookSubscriptions",
        "summary": "Elenca sottoscrizioni webhook",
        "tags": [
          "Webhooks"
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista sottoscrizioni",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookSubscriptionResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "7c1e2a90-3b4d-4f6a-8c2e-1d0f9b8a7e65",
                      "company_id": "550e8400-e29b-41d4-a716-446655440000",
                      "api_key_id": "b2c4e6f8-1a3c-4e5a-9b7d-0f2e4c6a8b10",
                      "name": "Sync gestionale",
                      "url": "https://gestionale.example.com/webhooks/esse24",
                      "secret_prefix": "whsec_3f",
                      "events": [
                        "orders.changed",
                        "orders.deleted",
                        "customers.changed",
                        "customers.deleted"
                      ],
                      "is_active": true,
                      "last_delivery_at": "2026-11-17T10:00:00.000Z",
                      "last_status_code": 200,
                      "created_at": "2026-11-17T09:00:00.000Z",
                      "updated_at": "2026-11-17T09:00:00.000Z"
                    }
                  ],
                  "meta": {
                    "request_id": "req_subs",
                    "total": 1,
                    "page": 1,
                    "per_page": 20,
                    "total_pages": 1
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "webhooks:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createWebhookSubscription",
        "summary": "Crea sottoscrizione webhook",
        "description": "Il `signing_secret` è restituito UNA SOLA VOLTA nella risposta di creazione. Firma: HMAC-SHA256(signing_secret, corpo grezzo), header `X-Esse24-Signature: sha256=<hex>`, nessun header di timestamp. Consegna almeno una volta (dedup su `X-Esse24-Delivery`), 2xx entro 10 s, 7 tentativi in circa 4 ore.",
        "tags": [
          "Webhooks"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWebhookSubscriptionRequest"
              },
              "example": {
                "name": "Sync gestionale",
                "url": "https://gestionale.example.com/webhooks/esse24",
                "events": [
                  "orders.changed",
                  "orders.deleted",
                  "customers.changed",
                  "customers.deleted"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Sottoscrizione creata (con signing_secret)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WebhookSubscriptionCreatedResponse"
                    },
                    "meta": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/RequestMeta"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "note": {
                              "type": "string"
                            }
                          }
                        }
                      ]
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "7c1e2a90-3b4d-4f6a-8c2e-1d0f9b8a7e65",
                    "company_id": "550e8400-e29b-41d4-a716-446655440000",
                    "api_key_id": "b2c4e6f8-1a3c-4e5a-9b7d-0f2e4c6a8b10",
                    "name": "Sync gestionale",
                    "url": "https://gestionale.example.com/webhooks/esse24",
                    "secret_prefix": "whsec_3f",
                    "events": [
                      "orders.changed",
                      "orders.deleted",
                      "customers.changed",
                      "customers.deleted"
                    ],
                    "is_active": true,
                    "last_delivery_at": null,
                    "last_status_code": null,
                    "created_at": "2026-11-17T09:00:00.000Z",
                    "updated_at": "2026-11-17T09:00:00.000Z",
                    "signing_secret": "whsec_3f2a9c..."
                  },
                  "meta": {
                    "request_id": "req_new_sub",
                    "note": "Store the signing_secret securely. It will not be shown again."
                  }
                }
              }
            }
          },
          "403": {
            "description": "INSUFFICIENT_SCOPE: un evento <risorsa>.changed / <risorsa>.deleted richiede lo scope di lettura di quella risorsa (lo stesso di GET /v1/changes)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore (URL non HTTPS, IP privato, ecc.)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "webhooks:write"
            ]
          }
        ]
      }
    },
    "/webhooks/subscriptions/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "patch": {
        "operationId": "updateWebhookSubscription",
        "summary": "Aggiorna sottoscrizione webhook",
        "tags": [
          "Webhooks"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateWebhookSubscriptionRequest"
              },
              "example": {
                "is_active": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sottoscrizione aggiornata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WebhookSubscriptionResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "sub-uuid",
                    "is_active": false,
                    "updated_at": "2026-06-13T10:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_upd_sub",
                    "timestamp": "2026-06-13T10:00:00.000Z"
                  }
                }
              }
            }
          },
          "403": {
            "description": "INSUFFICIENT_SCOPE: un evento nuovo richiede lo scope di lettura della sua risorsa. Spostare url da una chiave diversa da quella che ha creato la sottoscrizione richiede lo scope di lettura di ogni evento, ed e' negato se events e' vuoto (tutti gli eventi) o contiene eventi senza scope di lettura.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Non trovata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "webhooks:write"
            ]
          }
        ]
      },
      "delete": {
        "operationId": "deleteWebhookSubscription",
        "summary": "Elimina sottoscrizione webhook",
        "tags": [
          "Webhooks"
        ],
        "responses": {
          "204": {
            "description": "Eliminata"
          },
          "404": {
            "description": "Non trovata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "webhooks:write"
            ]
          }
        ]
      }
    },
    "/webhooks/subscriptions/{id}/replay": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "replayWebhookSubscription",
        "summary": "Ri-accoda eventi dead-letter",
        "description": "Rimette in coda TUTTI gli eventi in stato `dead` della sottoscrizione, con il contatore dei tentativi azzerato. Body vuoto: non esiste il replay di un singolo evento.",
        "tags": [
          "Webhooks"
        ],
        "responses": {
          "200": {
            "description": "Evento ri-accodati",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "replayed": {
                          "type": "boolean"
                        }
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "replayed": true
                  },
                  "meta": {
                    "request_id": "req_replay"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "webhooks:write"
            ]
          }
        ]
      }
    },
    "/webhooks/queue": {
      "get": {
        "operationId": "getWebhookQueueStatus",
        "summary": "Stato della coda di consegna, per sottoscrizione",
        "description": "Una riga per ogni sottoscrizione dell'azienda della chiave (attive e non, anche senza eventi in coda): quanti eventi sono `pending`, `failed`, `delivering` e `dead`, da quando aspetta il più vecchio e l'errore più frequente. Serve a chi riceve i webhook per accorgersi da sé che le consegne sono ferme: in funzionamento normale `oldest_waiting_at` è `null` o di pochi secondi; oltre i 15 minuti le consegne di quella sottoscrizione sono ferme, e `waiting_error` dice se dipende dal ricevente (`HTTP 500`, `Timeout (10s)`) o da esse24. Non è paginato.",
        "tags": [
          "Webhooks"
        ],
        "responses": {
          "200": {
            "description": "Stato della coda",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "subscription_id",
                          "name",
                          "is_active",
                          "pending",
                          "failed",
                          "delivering",
                          "dead"
                        ],
                        "properties": {
                          "subscription_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "name": {
                            "type": "string"
                          },
                          "is_active": {
                            "type": "boolean"
                          },
                          "last_delivery_at": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time"
                          },
                          "last_status_code": {
                            "type": [
                              "integer",
                              "null"
                            ]
                          },
                          "pending": {
                            "type": "integer",
                            "minimum": 0,
                            "description": "In coda, mai tentati"
                          },
                          "failed": {
                            "type": "integer",
                            "minimum": 0,
                            "description": "Tentati, in attesa del prossimo tentativo"
                          },
                          "delivering": {
                            "type": "integer",
                            "minimum": 0,
                            "description": "In consegna in questo momento"
                          },
                          "dead": {
                            "type": "integer",
                            "minimum": 0,
                            "description": "Abbandonati dopo 7 tentativi: restano finché non si chiama `replay`"
                          },
                          "oldest_waiting_at": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "Quando è entrato in coda il più vecchio evento `pending`, `failed` o `delivering`. `null` = niente in attesa"
                          },
                          "waiting_error": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "description": "L'ultimo errore più frequente fra gli eventi in attesa, con quante volte. Gli id dei record sono sostituiti da `{id}`",
                            "properties": {
                              "message": {
                                "type": "string"
                              },
                              "count": {
                                "type": "integer",
                                "minimum": 1
                              }
                            },
                            "required": [
                              "message",
                              "count"
                            ]
                          },
                          "oldest_dead_at": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time"
                          },
                          "dead_error": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "description": "Lo stesso per gli eventi `dead`",
                            "properties": {
                              "message": {
                                "type": "string"
                              },
                              "count": {
                                "type": "integer",
                                "minimum": 1
                              }
                            },
                            "required": [
                              "message",
                              "count"
                            ]
                          }
                        }
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "subscription_id": "7f3c2a10-1b2c-4d5e-8f90-123456789abc",
                      "name": "OPX sync",
                      "is_active": true,
                      "last_delivery_at": "2026-11-25T13:56:42.189Z",
                      "last_status_code": 200,
                      "pending": 118,
                      "failed": 2,
                      "delivering": 12,
                      "dead": 0,
                      "oldest_waiting_at": "2026-11-25T09:50:33.241Z",
                      "waiting_error": {
                        "message": "HTTP 500",
                        "count": 2
                      },
                      "oldest_dead_at": null,
                      "dead_error": null
                    }
                  ],
                  "meta": {
                    "request_id": "req_queue"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Scope `webhooks:read` mancante",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "webhooks:read"
            ]
          }
        ]
      }
    },
    "/receipts": {
      "get": {
        "operationId": "listReceiptClosures",
        "summary": "Elenca le chiusure giornaliere dei corrispettivi",
        "tags": [
          "Receipts"
        ],
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "description": "Data minima, `YYYY-MM-DD`.",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "Data massima, `YYYY-MM-DD`.",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "rt_serial",
            "in": "query",
            "description": "Matricola del registratore telematico.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Chiusure, dalla più recente",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ReceiptClosureListItem"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "uuid",
                      "business_date": "2026-06-14",
                      "rt_serial": "99MEY012345",
                      "z_number": 812,
                      "vat_register_number": 412,
                      "document_number": "COR-2026/412",
                      "taxable_total": 1180.33,
                      "vat_total": 219.67,
                      "total_amount": 1400,
                      "z_total": 1400,
                      "payment_cash": 620,
                      "payment_electronic": 780,
                      "journal_entry_id": "uuid"
                    }
                  ],
                  "meta": {
                    "page": 1,
                    "per_page": 20,
                    "total": 143
                  }
                }
              }
            }
          },
          "400": {
            "description": "`from` o `to` non sono nel formato `YYYY-MM-DD`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "receipts:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createReceiptClosure",
        "summary": "Registra una chiusura giornaliera",
        "description": "Registra lo Z della giornata. Rinviare lo stesso Z per la stessa matricola non duplica e non sovrascrive: risponde 409 con l'id gia' registrato.\n\nCosa produce dipende da come l'azienda tiene i corrispettivi:\n\n- **normale** — il server scrive le righe del registro IVA corrispettivi e, se la contabilizzazione e' attiva, la scrittura in prima nota;\n- **registrazione manuale dal cassetto fiscale** — la chiusura viene conservata (resta leggibile con GET, e la quadratura col rapporto Z viene fatta lo stesso) ma **non** genera ne' registro IVA ne' prima nota. La risposta e' comunque 201, con `warning` valorizzato e `vat_register_number`, `document_number`, `taxable_total`, `vat_total` e `journal_entry_id` a `null`, e `register_row_ids` vuoto.\n\nLa seconda modalita' esiste perche' chi registra i corrispettivi a mano leggendo dal cassetto fiscale scriverebbe l'IVA del mese due volte. Non si sceglie dalla chiamata: e' un'impostazione dell'azienda. **Un client che tratta quei campi come sempre valorizzati si rompe:** leggere prima `warning`.",
        "tags": [
          "Receipts"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateReceiptClosureRequest"
              },
              "example": {
                "business_date": "2026-06-14",
                "rt_serial": "99MEY012345",
                "z_number": 812,
                "z_total": 1400,
                "lines": [
                  {
                    "vat_code": "22",
                    "vat_rate": 22,
                    "taxable_amount": 1180.33,
                    "vat_amount": 219.67
                  }
                ],
                "voids_total": 12.5,
                "payments": {
                  "cash": 620,
                  "electronic": 780,
                  "unclaimed": 0,
                  "cheque": 0,
                  "voucher": 0,
                  "rounding": 0
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Chiusura registrata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CreateReceiptClosureResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "uuid",
                    "vat_register_number": 412,
                    "document_number": "COR-2026/412",
                    "business_date": "2026-06-14",
                    "taxable_total": 1180.33,
                    "vat_total": 219.67,
                    "total_amount": 1400,
                    "journal_entry_id": "uuid",
                    "register_row_ids": [
                      "uuid"
                    ]
                  },
                  "meta": {
                    "request_id": "req_rc2"
                  }
                }
              }
            }
          },
          "403": {
            "description": "La chiave non può scrivere corrispettivi per questa azienda",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Z già registrato per quella matricola, oppure periodo già liquidato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Quadratura Z fallita, codice IVA non configurato o payload non valido",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "receipts:write"
            ]
          }
        ]
      }
    },
    "/receipts/sales": {
      "get": {
        "operationId": "listRtReceipts",
        "summary": "Elenca gli scontrini del registratore",
        "description": "Gli scontrini singoli arrivati dal Portale, per consultazione. Con `rt_serial` e `z_number` restituisce quelli di una chiusura: serve al controllo di quadratura.",
        "tags": [
          "Receipts"
        ],
        "parameters": [
          {
            "name": "rt_serial",
            "in": "query",
            "description": "Matricola del registratore.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "z_number",
            "in": "query",
            "description": "Numero della chiusura Z.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "external_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "Data minima, `YYYY-MM-DD`.",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "Data massima, `YYYY-MM-DD`.",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 500
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Scontrini, per giornata, registratore, Z e numero",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "external_id",
                          "rt_serial",
                          "z_number",
                          "number",
                          "kind",
                          "document_date",
                          "total_amount"
                        ],
                        "properties": {
                          "external_id": {
                            "type": "string",
                            "maxLength": 100,
                            "description": "Chiave d'idempotenza: l'id del documento nel Portale."
                          },
                          "rt_serial": {
                            "type": "string",
                            "maxLength": 40,
                            "description": "Matricola del registratore. Con `z_number` aggancia lo scontrino alla chiusura."
                          },
                          "z_number": {
                            "type": "integer",
                            "minimum": 1
                          },
                          "number": {
                            "type": "integer",
                            "minimum": 1,
                            "description": "Numero del documento nella Z."
                          },
                          "kind": {
                            "type": "string",
                            "enum": [
                              "sale",
                              "return",
                              "void"
                            ],
                            "description": "Vendita, reso, annullo."
                          },
                          "document_date": {
                            "type": "string",
                            "format": "date",
                            "description": "La giornata fiscale."
                          },
                          "issued_at": {
                            "type": "string",
                            "format": "date-time",
                            "description": "L'ora di emissione, con offset."
                          },
                          "site_code": {
                            "type": "string",
                            "maxLength": 10
                          },
                          "total_amount": {
                            "type": "number",
                            "minimum": 0,
                            "description": "Positivo anche per reso e annullo: il verso lo dice `kind`."
                          },
                          "payments": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "required": [
                                "importo"
                              ],
                              "properties": {
                                "tipo": {
                                  "type": "integer"
                                },
                                "descrizione": {
                                  "type": "string"
                                },
                                "importo": {
                                  "type": "number"
                                }
                              }
                            }
                          },
                          "vat_summary": {
                            "type": "array",
                            "items": {
                              "type": "object"
                            }
                          },
                          "lines": {
                            "type": "array",
                            "maxItems": 300,
                            "items": {
                              "type": "object",
                              "required": [
                                "importo"
                              ],
                              "properties": {
                                "qta": {
                                  "type": "number"
                                },
                                "descrizione": {
                                  "type": "string",
                                  "description": "Come stampata dal registratore, che la tronca a circa 37 caratteri."
                                },
                                "prezzoUnitario": {
                                  "type": "number"
                                },
                                "importo": {
                                  "type": "number"
                                },
                                "aliquota": {
                                  "type": "number"
                                },
                                "natura": {
                                  "type": "string"
                                },
                                "reparto": {
                                  "type": "integer"
                                },
                                "codice": {
                                  "type": "string",
                                  "description": "Codice articolo, quando il Portale conosce la riga d'ordine."
                                },
                                "descrizione_completa": {
                                  "type": "string",
                                  "description": "Descrizione intera dalla riga d'ordine."
                                },
                                "rettifica": {
                                  "type": "boolean",
                                  "description": "Sconto o arrotondamento sul subtotale, non un articolo."
                                }
                              }
                            }
                          },
                          "ref_rt_serial": {
                            "type": "string",
                            "description": "Per reso e annullo: lo scontrino a cui si riferisce."
                          },
                          "ref_z_number": {
                            "type": "integer"
                          },
                          "ref_number": {
                            "type": "integer"
                          },
                          "ref_date": {
                            "type": "string",
                            "format": "date"
                          },
                          "order_code": {
                            "type": "string",
                            "maxLength": 60
                          },
                          "issued_by": {
                            "type": "string",
                            "maxLength": 200
                          }
                        }
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "uuid",
                      "external_id": "ae63e293-7257-4973-b72a-63213e89fa4e",
                      "rt_serial": "99IEB018491",
                      "z_number": 1650,
                      "number": 6,
                      "kind": "sale",
                      "document_date": "2026-10-26",
                      "issued_at": "2026-10-26T09:25:04+02:00",
                      "site_code": "00",
                      "total_amount": 6.3,
                      "payments": [
                        {
                          "tipo": 0,
                          "descrizione": "Contante",
                          "importo": 6.3
                        }
                      ],
                      "vat_summary": [
                        {
                          "aliquota": 22,
                          "natura": "",
                          "imponibile": 5.16,
                          "imposta": 1.14,
                          "lordo": 6.3
                        }
                      ],
                      "lines": [
                        {
                          "qta": 1,
                          "descrizione": "VALEX SPILLI PER CHIODATRICI MM30 CON",
                          "prezzoUnitario": 6.3,
                          "importo": 6.3,
                          "aliquota": 22,
                          "natura": "",
                          "reparto": 1,
                          "codice": "1464730",
                          "descrizione_completa": "VALEX SPILLI PER CHIODATRICI MM30 CONF. PZ 1000"
                        }
                      ],
                      "order_code": "RN-2026-012345",
                      "issued_by": "Mario Rossi",
                      "warning": null
                    }
                  ],
                  "meta": {
                    "page": 1,
                    "per_page": 100,
                    "total": 203
                  }
                }
              }
            }
          },
          "400": {
            "description": "`z_number`, `from` o `to` non validi",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "receipts:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "upsertRtReceipts",
        "summary": "Registra gli scontrini del registratore, a blocchi",
        "description": "Fino a 500 scontrini per chiamata. Upsert su `external_id`: rimandare uno scontrino non lo duplica e non dà errore. Uno scontrino non valido finisce in `rejected` e non ferma il blocco. Righe o pagamenti che non fanno `total_amount` non scartano lo scontrino: si registra com'è, con un `warning`. Non scrive registro IVA, prima nota né magazzino: quelli nascono dalla chiusura Z (`POST /receipts`).",
        "tags": [
          "Receipts"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "receipts"
                ],
                "properties": {
                  "receipts": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 500,
                    "items": {
                      "type": "object",
                      "required": [
                        "external_id",
                        "rt_serial",
                        "z_number",
                        "number",
                        "kind",
                        "document_date",
                        "total_amount"
                      ],
                      "properties": {
                        "external_id": {
                          "type": "string",
                          "maxLength": 100,
                          "description": "Chiave d'idempotenza: l'id del documento nel Portale."
                        },
                        "rt_serial": {
                          "type": "string",
                          "maxLength": 40,
                          "description": "Matricola del registratore. Con `z_number` aggancia lo scontrino alla chiusura."
                        },
                        "z_number": {
                          "type": "integer",
                          "minimum": 1
                        },
                        "number": {
                          "type": "integer",
                          "minimum": 1,
                          "description": "Numero del documento nella Z."
                        },
                        "kind": {
                          "type": "string",
                          "enum": [
                            "sale",
                            "return",
                            "void"
                          ],
                          "description": "Vendita, reso, annullo."
                        },
                        "document_date": {
                          "type": "string",
                          "format": "date",
                          "description": "La giornata fiscale."
                        },
                        "issued_at": {
                          "type": "string",
                          "format": "date-time",
                          "description": "L'ora di emissione, con offset."
                        },
                        "site_code": {
                          "type": "string",
                          "maxLength": 10
                        },
                        "total_amount": {
                          "type": "number",
                          "minimum": 0,
                          "description": "Positivo anche per reso e annullo: il verso lo dice `kind`."
                        },
                        "payments": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "importo"
                            ],
                            "properties": {
                              "tipo": {
                                "type": "integer"
                              },
                              "descrizione": {
                                "type": "string"
                              },
                              "importo": {
                                "type": "number"
                              }
                            }
                          }
                        },
                        "vat_summary": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        },
                        "lines": {
                          "type": "array",
                          "maxItems": 300,
                          "items": {
                            "type": "object",
                            "required": [
                              "importo"
                            ],
                            "properties": {
                              "qta": {
                                "type": "number"
                              },
                              "descrizione": {
                                "type": "string",
                                "description": "Come stampata dal registratore, che la tronca a circa 37 caratteri."
                              },
                              "prezzoUnitario": {
                                "type": "number"
                              },
                              "importo": {
                                "type": "number"
                              },
                              "aliquota": {
                                "type": "number"
                              },
                              "natura": {
                                "type": "string"
                              },
                              "reparto": {
                                "type": "integer"
                              },
                              "codice": {
                                "type": "string",
                                "description": "Codice articolo, quando il Portale conosce la riga d'ordine."
                              },
                              "descrizione_completa": {
                                "type": "string",
                                "description": "Descrizione intera dalla riga d'ordine."
                              },
                              "rettifica": {
                                "type": "boolean",
                                "description": "Sconto o arrotondamento sul subtotale, non un articolo."
                              }
                            }
                          }
                        },
                        "ref_rt_serial": {
                          "type": "string",
                          "description": "Per reso e annullo: lo scontrino a cui si riferisce."
                        },
                        "ref_z_number": {
                          "type": "integer"
                        },
                        "ref_number": {
                          "type": "integer"
                        },
                        "ref_date": {
                          "type": "string",
                          "format": "date"
                        },
                        "order_code": {
                          "type": "string",
                          "maxLength": 60
                        },
                        "issued_by": {
                          "type": "string",
                          "maxLength": 200
                        }
                      }
                    }
                  }
                }
              },
              "example": {
                "receipts": [
                  {
                    "external_id": "ae63e293-7257-4973-b72a-63213e89fa4e",
                    "rt_serial": "99IEB018491",
                    "z_number": 1650,
                    "number": 6,
                    "kind": "sale",
                    "document_date": "2026-10-26",
                    "issued_at": "2026-10-26T09:25:04+02:00",
                    "site_code": "00",
                    "total_amount": 6.3,
                    "payments": [
                      {
                        "tipo": 0,
                        "descrizione": "Contante",
                        "importo": 6.3
                      }
                    ],
                    "vat_summary": [
                      {
                        "aliquota": 22,
                        "natura": "",
                        "imponibile": 5.16,
                        "imposta": 1.14,
                        "lordo": 6.3
                      }
                    ],
                    "lines": [
                      {
                        "qta": 1,
                        "descrizione": "VALEX SPILLI PER CHIODATRICI MM30 CON",
                        "prezzoUnitario": 6.3,
                        "importo": 6.3,
                        "aliquota": 22,
                        "natura": "",
                        "reparto": 1,
                        "codice": "1464730",
                        "descrizione_completa": "VALEX SPILLI PER CHIODATRICI MM30 CONF. PZ 1000"
                      }
                    ],
                    "order_code": "RN-2026-012345",
                    "issued_by": "Mario Rossi"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Esito del blocco",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "inserted": {
                          "type": "integer"
                        },
                        "updated": {
                          "type": "integer"
                        },
                        "rejected": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "external_id": {
                                "type": "string"
                              },
                              "reason": {
                                "type": "string"
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": {
                    "inserted": 498,
                    "updated": 1,
                    "rejected": [
                      {
                        "external_id": "b1c2d3e4-0000-4000-8000-000000000000",
                        "reason": "receipts[17]: 'kind' must be 'sale', 'return' or 'void'"
                      }
                    ]
                  }
                }
              }
            }
          },
          "422": {
            "description": "`receipts` assente, vuoto o con più di 500 scontrini",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "receipts:write"
            ]
          }
        ]
      }
    },
    "/receipts/documents": {
      "get": {
        "operationId": "listReceiptDocuments",
        "summary": "Elenca le ricevute senza registratore",
        "description": "Ricevute registrate con POST /receipts/documents (vendite web ai privati), per data e numero decrescenti. Gli articoli (`items`) mandati alla creazione non sono restituiti.",
        "tags": [
          "Receipts"
        ],
        "parameters": [
          {
            "name": "external_id",
            "in": "query",
            "description": "Match esatto sulla chiave d'idempotenza.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "Data minima, `YYYY-MM-DD`.",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "Data massima, `YYYY-MM-DD`.",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ricevute",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ReceiptDocumentResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "c7d8e9f0-1a2b-4c3d-8e4f-5a6b7c8d9e0f",
                      "section_id": "0f1e2d3c-4b5a-4968-8776-655443322110",
                      "fiscal_year": 2026,
                      "number": 1592,
                      "document_number": "1592/SW",
                      "document_date": "2026-10-03",
                      "external_id": "8c5603f2-76e8-421d-bf2f-27d966bde2bf",
                      "customer_id": null,
                      "customer_name": "Mario Rossi",
                      "delivery_reference": "BOL-2026-7781",
                      "order_reference": "WEB-100234",
                      "payment_method": "carta",
                      "taxable_total": 69.88,
                      "vat_total": 15.38,
                      "total_amount": 85.26,
                      "lines": [
                        {
                          "kind": "goods",
                          "vat_rate": 22,
                          "taxable_amount": 61.77,
                          "vat_amount": 13.59
                        },
                        {
                          "kind": "shipping",
                          "vat_rate": 22,
                          "taxable_amount": 8.11,
                          "vat_amount": 1.79
                        }
                      ],
                      "vat_register_number": 412,
                      "journal_entry_id": "d1e2f3a4-b5c6-4d7e-8f90-a1b2c3d4e5f6",
                      "status": "registered",
                      "warning": null,
                      "notes": null,
                      "created_at": "2026-10-03T16:40:11.000Z",
                      "updated_at": "2026-10-03T16:40:11.000Z"
                    }
                  ],
                  "meta": {
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "total": 1,
                    "page": 1,
                    "per_page": 20,
                    "total_pages": 1
                  }
                }
              }
            }
          },
          "400": {
            "description": "`from` o `to` non nel formato `YYYY-MM-DD`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "VALIDATION_ERROR",
                    "message": "Query param 'from' must be YYYY-MM-DD.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "receipts:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createReceiptDocument",
        "summary": "Registra una ricevuta senza registratore (o il suo storno)",
        "description": "Una ricevuta col numero del sezionale corrispettivi che il cliente ha in mano (es. `1592/SW`): scrive il registro dei corrispettivi e la scrittura contabile. Con `reverses_external_id` è lo storno di una ricevuta già registrata: importi negativi, stesso sezionale, `refunded: false` quando il cliente non è rimborsato ma riceve la fattura. La somma delle righe (imponibile + IVA) deve coincidere al centesimo con `total`. Lo stesso `external_id` rimandato risponde 409 senza toccare nulla. Emette l'evento `receipts.document.created`.",
        "tags": [
          "Receipts"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "section_code",
                  "number",
                  "document_date",
                  "external_id",
                  "total",
                  "lines"
                ],
                "properties": {
                  "section_code": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9]{1,10}$",
                    "description": "Codice del sezionale corrispettivi, es. `SW`."
                  },
                  "number": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "document_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "external_id": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Chiave d'idempotenza della ricevuta."
                  },
                  "reverses_external_id": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "Rende la ricevuta uno storno di quella con questo `external_id`."
                  },
                  "refunded": {
                    "type": "boolean",
                    "default": true,
                    "description": "Solo per lo storno. `false` = nessun rimborso, il cliente riceve la fattura."
                  },
                  "total": {
                    "type": "number",
                    "description": "Al massimo 2 decimali. Positivo; negativo per lo storno."
                  },
                  "lines": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 40,
                    "items": {
                      "type": "object",
                      "required": [
                        "vat_rate",
                        "taxable_amount",
                        "vat_amount"
                      ],
                      "properties": {
                        "kind": {
                          "type": "string",
                          "enum": [
                            "goods",
                            "shipping"
                          ],
                          "default": "goods"
                        },
                        "vat_rate": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 100
                        },
                        "vat_code": {
                          "type": "string",
                          "maxLength": 20
                        },
                        "taxable_amount": {
                          "type": "number",
                          "description": "2 decimali; ≤ 0 nello storno."
                        },
                        "vat_amount": {
                          "type": "number",
                          "description": "2 decimali; ≤ 0 nello storno."
                        }
                      }
                    }
                  },
                  "items": {
                    "type": "array",
                    "maxItems": 300,
                    "description": "Articoli della ricevuta, IVA compresa, per la stampa e la scheda. Registro e scrittura nascono da `lines`.",
                    "items": {
                      "type": "object",
                      "required": [
                        "description",
                        "quantity",
                        "line_total"
                      ],
                      "properties": {
                        "code": {
                          "type": "string",
                          "maxLength": 80
                        },
                        "description": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 300
                        },
                        "quantity": {
                          "type": "number"
                        },
                        "unit_price": {
                          "type": "number",
                          "description": "IVA compresa."
                        },
                        "discount_percent": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 100
                        },
                        "vat_rate": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 100
                        },
                        "line_total": {
                          "type": "number",
                          "description": "IVA compresa, 2 decimali."
                        }
                      }
                    }
                  },
                  "customer_code": {
                    "type": "string",
                    "maxLength": 40
                  },
                  "customer_name": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "delivery_reference": {
                    "type": "string",
                    "maxLength": 60
                  },
                  "order_reference": {
                    "type": "string",
                    "maxLength": 60
                  },
                  "payment_method": {
                    "type": "string",
                    "maxLength": 40
                  },
                  "notes": {
                    "type": "string",
                    "maxLength": 500
                  }
                }
              },
              "example": {
                "section_code": "SW",
                "number": 1592,
                "document_date": "2026-10-03",
                "external_id": "8c5603f2-76e8-421d-bf2f-27d966bde2bf",
                "total": 85.26,
                "lines": [
                  {
                    "kind": "goods",
                    "vat_rate": 22,
                    "taxable_amount": 61.77,
                    "vat_amount": 13.59
                  },
                  {
                    "kind": "shipping",
                    "vat_rate": 22,
                    "taxable_amount": 8.11,
                    "vat_amount": 1.79
                  }
                ],
                "items": [
                  {
                    "code": "VT-M8-40",
                    "description": "Viti M8x40 zincate (conf. 100)",
                    "quantity": 3,
                    "unit_price": 25.13,
                    "line_total": 75.36,
                    "vat_rate": 22
                  }
                ],
                "customer_name": "Mario Rossi",
                "delivery_reference": "BOL-2026-7781",
                "order_reference": "WEB-100234",
                "payment_method": "carta"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Ricevuta registrata. Per uno storno ci sono in più `reverses_id`, `reverses_document_number`, `refund_entry_id`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "document_number": {
                          "type": "string"
                        },
                        "vat_register_number": {
                          "type": "integer",
                          "nullable": true
                        },
                        "document_date": {
                          "type": "string",
                          "format": "date"
                        },
                        "external_id": {
                          "type": "string"
                        },
                        "taxable_total": {
                          "type": "number"
                        },
                        "vat_total": {
                          "type": "number"
                        },
                        "total_amount": {
                          "type": "number"
                        },
                        "journal_entry_id": {
                          "type": "string",
                          "format": "uuid",
                          "nullable": true
                        },
                        "warning": {
                          "type": "string",
                          "nullable": true
                        },
                        "register_row_ids": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "format": "uuid"
                          }
                        },
                        "reverses_id": {
                          "type": "string",
                          "format": "uuid",
                          "description": "Solo storno."
                        },
                        "reverses_document_number": {
                          "type": "string",
                          "description": "Solo storno."
                        },
                        "refund_entry_id": {
                          "type": "string",
                          "format": "uuid",
                          "nullable": true,
                          "description": "Solo storno: scrittura del rimborso, `null` se l'originale non era incassato o `refunded` è `false`."
                        }
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "c7d8e9f0-1a2b-4c3d-8e4f-5a6b7c8d9e0f",
                    "document_number": "1592/SW",
                    "vat_register_number": 412,
                    "document_date": "2026-10-03",
                    "external_id": "8c5603f2-76e8-421d-bf2f-27d966bde2bf",
                    "taxable_total": 69.88,
                    "vat_total": 15.38,
                    "total_amount": 85.26,
                    "journal_entry_id": "d1e2f3a4-b5c6-4d7e-8f90-a1b2c3d4e5f6",
                    "warning": null,
                    "register_row_ids": [
                      "e1f2a3b4-c5d6-4e7f-8a9b-0c1d2e3f4a5b"
                    ]
                  },
                  "meta": {
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10"
                  }
                }
              }
            }
          },
          "403": {
            "description": "La chiave non può scrivere ricevute per questa azienda",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "FORBIDDEN",
                    "message": "This API key cannot write receipts for this company.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          },
          "409": {
            "description": "`CONFLICT`: stesso `external_id` già registrato (l'errore porta `existing_id`, `existing_document_number`, `existing_vat_register_number`, `existing_total_amount`). `NUMBER_TAKEN`: numero già nel registro del sezionale. `PERIOD_CLOSED`: periodo IVA già liquidato.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "CONFLICT",
                    "message": "Receipt '8c5603f2-76e8-421d-bf2f-27d966bde2bf' is already registered as 1592/SW.",
                    "existing_id": "c7d8e9f0-1a2b-4c3d-8e4f-5a6b7c8d9e0f",
                    "existing_document_number": "1592/SW",
                    "existing_vat_register_number": 412,
                    "existing_total_amount": 85.26,
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          },
          "422": {
            "description": "`VALIDATION_ERROR`: campo mancante o malformato, righe che non fanno il totale, storno non applicabile. `VAT_CODE_NOT_CONFIGURED`: aliquota o codice IVA non configurato per l'azienda.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "VALIDATION_ERROR",
                    "message": "Lines add up to 85.25 but 'total' declares 85.26. They must match to the cent.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "receipts:write"
            ]
          }
        ]
      }
    },
    "/receipts/documents/{id}": {
      "get": {
        "operationId": "getReceiptDocument",
        "summary": "Dettaglio di una ricevuta senza registratore",
        "description": "Una ricevuta registrata non si modifica: si storna con una nuova ricevuta (`reverses_external_id`).",
        "tags": [
          "Receipts"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ricevuta",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ReceiptDocumentResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "c7d8e9f0-1a2b-4c3d-8e4f-5a6b7c8d9e0f",
                    "section_id": "0f1e2d3c-4b5a-4968-8776-655443322110",
                    "fiscal_year": 2026,
                    "number": 1592,
                    "document_number": "1592/SW",
                    "document_date": "2026-10-03",
                    "external_id": "8c5603f2-76e8-421d-bf2f-27d966bde2bf",
                    "customer_id": null,
                    "customer_name": "Mario Rossi",
                    "delivery_reference": "BOL-2026-7781",
                    "order_reference": "WEB-100234",
                    "payment_method": "carta",
                    "taxable_total": 69.88,
                    "vat_total": 15.38,
                    "total_amount": 85.26,
                    "lines": [
                      {
                        "kind": "goods",
                        "vat_rate": 22,
                        "taxable_amount": 61.77,
                        "vat_amount": 13.59
                      },
                      {
                        "kind": "shipping",
                        "vat_rate": 22,
                        "taxable_amount": 8.11,
                        "vat_amount": 1.79
                      }
                    ],
                    "vat_register_number": 412,
                    "journal_entry_id": "d1e2f3a4-b5c6-4d7e-8f90-a1b2c3d4e5f6",
                    "status": "registered",
                    "warning": null,
                    "notes": null,
                    "created_at": "2026-10-03T16:40:11.000Z",
                    "updated_at": "2026-10-03T16:40:11.000Z"
                  },
                  "meta": {
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Id non UUID",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "VALIDATION_ERROR",
                    "message": "Invalid ID format. Must be a valid UUID.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Ricevuta inesistente per questa azienda",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "NOT_FOUND",
                    "message": "Receipt document 'c7d8e9f0-1a2b-4c3d-8e4f-5a6b7c8d9e0f' not found.",
                    "request_id": "0b6c2f4e-7d1a-4c55-9a3e-2f1d8e6b9c10",
                    "docs_url": "https://app.esse24.com/documentation/api#api-errori"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "receipts:read"
            ]
          }
        ]
      }
    },
    "/receipts/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getReceiptClosure",
        "summary": "Ottieni una chiusura (con il castelletto)",
        "tags": [
          "Receipts"
        ],
        "responses": {
          "200": {
            "description": "Chiusura con le righe per aliquota",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ReceiptClosureResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "uuid",
                    "business_date": "2026-06-14",
                    "rt_serial": "99MEY012345",
                    "z_number": 812,
                    "total_amount": 1400,
                    "lines": [
                      {
                        "id": "uuid",
                        "vat_code": "22",
                        "vat_rate": 22,
                        "taxable_amount": 1180.33,
                        "vat_amount": 219.67,
                        "total_amount": 1400
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_rc1"
                  }
                }
              }
            }
          },
          "400": {
            "description": "`id` non è un UUID",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Chiusura non trovata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "receipts:read"
            ]
          }
        ]
      }
    },
    "/delivery-notes": {
      "get": {
        "operationId": "listDeliveryNotes",
        "summary": "Elenca DDT di vendita",
        "description": "Solo DDT di vendita (counterparty_kind = 'customer'), dal piu' recente. La lista non include le righe: per quelle serve GET /delivery-notes/{id}.",
        "tags": [
          "Delivery Notes"
        ],
        "parameters": [
          {
            "name": "external_id",
            "in": "query",
            "description": "Match esatto sull'id del documento nel sistema mittente. E' la chiave con cui si ripesca il DDT dopo un timeout, quando non si sa se il POST era passato.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "ddt_number",
            "in": "query",
            "description": "Match esatto sul numero documento.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "in_transit",
                "delivered",
                "invoiced",
                "cancelled"
              ]
            }
          },
          {
            "name": "billing_status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "unbilled",
                "to_invoice",
                "not_billable",
                "billed"
              ]
            }
          },
          {
            "name": "customer_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "customer_reference",
            "in": "query",
            "description": "Commessa, match esatto. Serve a chi costruisce i gruppi di fatturazione.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "destination_ref",
            "in": "query",
            "description": "Destinazione, match esatto.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sede_operativa",
            "in": "query",
            "description": "Sede emittente, match esatto.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "date_from",
            "in": "query",
            "description": "Filtra su issue_date (inclusivo).",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "date_to",
            "in": "query",
            "description": "Filtra su issue_date (inclusivo).",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista DDT di vendita (senza righe)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/DeliveryNoteResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "ddt-uuid-001",
                      "company_id": "company-uuid",
                      "customer_id": "cust-uuid",
                      "invoice_id": null,
                      "ddt_number": "DDT/00/2026/1234",
                      "issue_date": "2026-09-15",
                      "delivery_date": "2026-09-15",
                      "transport_reason": "Vendita",
                      "transport_method": "Mittente",
                      "carrier": null,
                      "packages_count": 3,
                      "weight": 42.5,
                      "appearance": "Bancali",
                      "delivery_address": {
                        "street": "Via Roma 12",
                        "city": "Cuneo",
                        "postal_code": "12100",
                        "province": "CN",
                        "country": "IT"
                      },
                      "notes": null,
                      "status": "delivered",
                      "billing_status": "unbilled",
                      "billed_at": null,
                      "total_amount": 1220,
                      "order_number": "ORD-2026-0099",
                      "job_code": null,
                      "external_id": "PORTALE-DDT-88213",
                      "counterparty_kind": "customer",
                      "discount_footer_pct": null,
                      "discount_footer_amount": null,
                      "inventory_posted_at": null,
                      "customer_reference": "COMMESSA-7781",
                      "contact_person": "Marta Bianchi",
                      "destination_ref": "Cantiere Borgo",
                      "sede_operativa": "Cervasca",
                      "created_at": "2026-09-15T08:12:00.000Z",
                      "updated_at": "2026-09-15T08:12:00.000Z",
                      "order_reference": "ORD-PA-2026-88",
                      "order_date": "2026-09-01",
                      "codice_commessa_convenzione": "CONV-2026-12",
                      "cig": "Z1A2B3C4D5",
                      "cup": "J51B21000320006"
                    }
                  ],
                  "meta": {
                    "request_id": "req_delivery_notes",
                    "total": 1243,
                    "page": 1,
                    "per_page": 50,
                    "total_pages": 25
                  }
                }
              }
            }
          },
          "400": {
            "description": "Parametro di query non valido (date_from / date_to fuori dal formato YYYY-MM-DD)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "delivery-notes:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createDeliveryNote",
        "summary": "Registra un DDT di vendita emesso fuori",
        "description": "Rispecchia in esse24 un DDT emesso da un altro sistema. 'external_id' e 'ddt_number' sono obbligatori: il primo rende la chiamata ripetibile, il secondo tiene il numero della serie di chi emette. Il magazzino non si muove (nessun 'warehouse_id' in ingresso, nessuna scrittura di inventario). I totali li calcola esse24 dalle righe: lo sconto di chiusura in percentuale vince su quello in importo e scala anche l'IVA. Un secondo POST con lo stesso 'external_id' risponde 409 con l'id gia' registrato, cosi' la coda del mittente chiude il job invece di ritentare.",
        "tags": [
          "Delivery Notes"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateDeliveryNoteRequest"
              },
              "example": {
                "customer_id": "cust-uuid",
                "external_id": "PORTALE-DDT-88213",
                "ddt_number": "DDT/00/2026/1234",
                "issue_date": "2026-09-15",
                "delivery_date": "2026-09-15",
                "status": "delivered",
                "billing_status": "unbilled",
                "transport_reason": "Vendita",
                "transport_method": "Mittente",
                "packages_count": 3,
                "weight": 42.5,
                "appearance": "Bancali",
                "delivery_address": {
                  "street": "Via Roma 12",
                  "city": "Cuneo",
                  "postal_code": "12100",
                  "province": "CN",
                  "country": "IT"
                },
                "order_number": "ORD-2026-0099",
                "customer_reference": "COMMESSA-7781",
                "contact_person": "Marta Bianchi",
                "destination_ref": "Cantiere Borgo",
                "sede_operativa": "Cervasca",
                "order_reference": "ORD-PA-2026-88",
                "order_date": "2026-09-01",
                "codice_commessa_convenzione": "CONV-2026-12",
                "cig": "Z1A2B3C4D5",
                "cup": "J51B21000320006",
                "items": [
                  {
                    "item_code": "VT-M8-40",
                    "description": "Viti M8x40 zincate",
                    "quantity": 200,
                    "uom": "PZ",
                    "unit_price": 5,
                    "discount_percent": 0,
                    "vat_rate": 22
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "DDT registrato (con righe)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/DeliveryNoteResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "ddt-uuid-001",
                    "company_id": "company-uuid",
                    "customer_id": "cust-uuid",
                    "invoice_id": null,
                    "ddt_number": "DDT/00/2026/1234",
                    "issue_date": "2026-09-15",
                    "delivery_date": "2026-09-15",
                    "transport_reason": "Vendita",
                    "transport_method": "Mittente",
                    "carrier": null,
                    "packages_count": 3,
                    "weight": 42.5,
                    "appearance": "Bancali",
                    "delivery_address": {
                      "street": "Via Roma 12",
                      "city": "Cuneo",
                      "postal_code": "12100",
                      "province": "CN",
                      "country": "IT"
                    },
                    "notes": null,
                    "status": "delivered",
                    "billing_status": "unbilled",
                    "billed_at": null,
                    "total_amount": 1220,
                    "order_number": "ORD-2026-0099",
                    "job_code": null,
                    "external_id": "PORTALE-DDT-88213",
                    "counterparty_kind": "customer",
                    "discount_footer_pct": null,
                    "discount_footer_amount": null,
                    "inventory_posted_at": null,
                    "customer_reference": "COMMESSA-7781",
                    "contact_person": "Marta Bianchi",
                    "destination_ref": "Cantiere Borgo",
                    "sede_operativa": "Cervasca",
                    "created_at": "2026-09-15T08:12:00.000Z",
                    "updated_at": "2026-09-15T08:12:00.000Z",
                    "order_reference": "ORD-PA-2026-88",
                    "order_date": "2026-09-01",
                    "codice_commessa_convenzione": "CONV-2026-12",
                    "cig": "Z1A2B3C4D5",
                    "cup": "J51B21000320006",
                    "items": [
                      {
                        "id": "ddtline-uuid-001",
                        "delivery_note_id": "ddt-uuid-001",
                        "line_number": 1,
                        "item_code": "VT-M8-40",
                        "description": "Viti M8x40 zincate",
                        "quantity": 200,
                        "uom": "PZ",
                        "unit_price": 5,
                        "discount_percent": 0,
                        "vat_rate": 22,
                        "line_total": 1000,
                        "created_at": "2026-09-15T08:12:00.000Z"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_delivery_notes"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Esiste gia' un DDT con questo 'external_id'. Il messaggio riporta id e numero del documento registrato: si recupera con GET /delivery-notes?external_id=…",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "CONFLICT",
                    "message": "A delivery note with external_id 'PORTALE-DDT-88213' already exists (id ddt-uuid-001, number DDT/00/2026/1234). Use GET /delivery-notes?external_id=… to retrieve it."
                  },
                  "meta": {
                    "request_id": "req_delivery_notes"
                  }
                }
              }
            }
          },
          "422": {
            "description": "Payload non valido (campi obbligatori, righe, sconti, forma di delivery_address)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "delivery-notes:write"
            ]
          }
        ]
      }
    },
    "/delivery-notes/{id}": {
      "get": {
        "operationId": "getDeliveryNote",
        "summary": "Dettaglio DDT di vendita",
        "tags": [
          "Delivery Notes"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "DDT con le righe",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/DeliveryNoteResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "ddt-uuid-001",
                    "company_id": "company-uuid",
                    "customer_id": "cust-uuid",
                    "invoice_id": null,
                    "ddt_number": "DDT/00/2026/1234",
                    "issue_date": "2026-09-15",
                    "delivery_date": "2026-09-15",
                    "transport_reason": "Vendita",
                    "transport_method": "Mittente",
                    "carrier": null,
                    "packages_count": 3,
                    "weight": 42.5,
                    "appearance": "Bancali",
                    "delivery_address": {
                      "street": "Via Roma 12",
                      "city": "Cuneo",
                      "postal_code": "12100",
                      "province": "CN",
                      "country": "IT"
                    },
                    "notes": null,
                    "status": "delivered",
                    "billing_status": "unbilled",
                    "billed_at": null,
                    "total_amount": 1220,
                    "order_number": "ORD-2026-0099",
                    "job_code": null,
                    "external_id": "PORTALE-DDT-88213",
                    "counterparty_kind": "customer",
                    "discount_footer_pct": null,
                    "discount_footer_amount": null,
                    "inventory_posted_at": null,
                    "customer_reference": "COMMESSA-7781",
                    "contact_person": "Marta Bianchi",
                    "destination_ref": "Cantiere Borgo",
                    "sede_operativa": "Cervasca",
                    "created_at": "2026-09-15T08:12:00.000Z",
                    "updated_at": "2026-09-15T08:12:00.000Z",
                    "order_reference": "ORD-PA-2026-88",
                    "order_date": "2026-09-01",
                    "codice_commessa_convenzione": "CONV-2026-12",
                    "cig": "Z1A2B3C4D5",
                    "cup": "J51B21000320006",
                    "items": [
                      {
                        "id": "ddtline-uuid-001",
                        "delivery_note_id": "ddt-uuid-001",
                        "line_number": 1,
                        "item_code": "VT-M8-40",
                        "description": "Viti M8x40 zincate",
                        "quantity": 200,
                        "uom": "PZ",
                        "unit_price": 5,
                        "discount_percent": 0,
                        "vat_rate": 22,
                        "line_total": 1000,
                        "created_at": "2026-09-15T08:12:00.000Z"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_delivery_notes"
                  }
                }
              }
            }
          },
          "404": {
            "description": "DDT inesistente per questa azienda",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "delivery-notes:read"
            ]
          }
        ]
      },
      "patch": {
        "operationId": "updateDeliveryNote",
        "summary": "Aggiorna un DDT di vendita",
        "description": "Un DDT gia' fatturato non si modifica: le sue righe sono dentro una fattura con un numero fiscale, e si rettifica con una nota di credito (409, anche se il PATCH ripete proforma_id: nessun campo viene scritto). Eccezione: se la fattura del DDT e' ancora la bozza nata da proforma_id, il PATCH si applica e la bozza si rifa' dal DDT corretto, con un nuovo invoice_id; se la bozza non si puo' rifare il DDT resta salvato e la risposta e' 409 con il motivo. Quando il payload contiene 'items' la sostituzione e' integrale — le righe vecchie vengono cancellate e i totali ricalcolati — e lo sconto di chiusura usato e' quello del payload se c'e', altrimenti quello gia' salvato.",
        "tags": [
          "Delivery Notes"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateDeliveryNoteRequest"
              },
              "example": {
                "delivery_date": "2026-09-16",
                "status": "delivered",
                "destination_ref": "Cantiere Borgo — lotto 2",
                "items": [
                  {
                    "item_code": "VT-M8-40",
                    "description": "Viti M8x40 zincate",
                    "quantity": 180,
                    "uom": "PZ",
                    "unit_price": 5,
                    "discount_percent": 0,
                    "vat_rate": 22
                  }
                ],
                "cig": "Z1A2B3C4D5",
                "order_reference": "ORD-PA-2026-88"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "DDT aggiornato (con righe)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/DeliveryNoteResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "ddt-uuid-001",
                    "company_id": "company-uuid",
                    "customer_id": "cust-uuid",
                    "invoice_id": null,
                    "ddt_number": "DDT/00/2026/1234",
                    "issue_date": "2026-09-15",
                    "delivery_date": "2026-09-16",
                    "transport_reason": "Vendita",
                    "transport_method": "Mittente",
                    "carrier": null,
                    "packages_count": 3,
                    "weight": 42.5,
                    "appearance": "Bancali",
                    "delivery_address": {
                      "street": "Via Roma 12",
                      "city": "Cuneo",
                      "postal_code": "12100",
                      "province": "CN",
                      "country": "IT"
                    },
                    "notes": null,
                    "status": "delivered",
                    "billing_status": "unbilled",
                    "billed_at": null,
                    "total_amount": 1220,
                    "order_number": "ORD-2026-0099",
                    "job_code": null,
                    "external_id": "PORTALE-DDT-88213",
                    "counterparty_kind": "customer",
                    "discount_footer_pct": null,
                    "discount_footer_amount": null,
                    "inventory_posted_at": null,
                    "customer_reference": "COMMESSA-7781",
                    "contact_person": "Marta Bianchi",
                    "destination_ref": "Cantiere Borgo",
                    "sede_operativa": "Cervasca",
                    "created_at": "2026-09-15T08:12:00.000Z",
                    "updated_at": "2026-09-15T08:12:00.000Z",
                    "order_reference": "ORD-PA-2026-88",
                    "order_date": "2026-09-01",
                    "codice_commessa_convenzione": "CONV-2026-12",
                    "cig": "Z1A2B3C4D5",
                    "cup": "J51B21000320006",
                    "items": [
                      {
                        "id": "ddtline-uuid-001",
                        "delivery_note_id": "ddt-uuid-001",
                        "line_number": 1,
                        "item_code": "VT-M8-40",
                        "description": "Viti M8x40 zincate",
                        "quantity": 200,
                        "uom": "PZ",
                        "unit_price": 5,
                        "discount_percent": 0,
                        "vat_rate": 22,
                        "line_total": 1000,
                        "created_at": "2026-09-15T08:12:00.000Z"
                      }
                    ]
                  },
                  "meta": {
                    "request_id": "req_delivery_notes"
                  }
                }
              }
            }
          },
          "404": {
            "description": "DDT inesistente per questa azienda",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "DDT gia' fatturato da una fattura confermata (si rettifica con una nota di credito), oppure DDT salvato ma bozza della proforma non rifatta",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "CONFLICT",
                    "message": "Delivery note 'ddt-uuid-001' is already invoiced by invoice 'FT-2026-00123' (status 'issued'): no change was applied. Issue a credit note instead."
                  },
                  "meta": {
                    "request_id": "req_delivery_notes"
                  }
                }
              }
            }
          },
          "422": {
            "description": "Payload non valido o nessun campo aggiornabile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "delivery-notes:write"
            ]
          }
        ]
      }
    },
    "/invoices/{id}/payments": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "registerInvoicePayment",
        "summary": "Registra l incasso di una fattura emessa",
        "tags": [
          "Invoices"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RegisterPaymentRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Incasso registrato (o niente da applicare)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/InvoiceResponse"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "applied_now": {
                              "type": "number",
                              "description": "Quanto ha applicato QUESTA chiamata: 0 se non restava nulla da applicare"
                            },
                            "collection": {
                              "type": "string",
                              "enum": [
                                "manual"
                              ],
                              "description": "Presente solo quando l'incasso lo registra la contabilità (l'azienda ha scelto di non registrare gli incassi dalle API, oppure il metodo si registra dalla banca): non è stato applicato niente e la fattura resta aperta"
                            }
                          }
                        }
                      ]
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "uuid",
                    "invoice_number": "201213",
                    "status": "issued",
                    "total_amount": 100.77,
                    "payment_status": "paid",
                    "paid_amount": 100.77,
                    "payment_date": "2026-10-05",
                    "applied_now": 100.77
                  },
                  "meta": {
                    "request_id": "req_pay1"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Non trovata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Bozza, senza scadenze, gia riscossa dalle condizioni di pagamento, oppure nota di credito",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Campo non valido o sconosciuto",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "invoices:write"
            ]
          }
        ]
      }
    },
    "/delivery-notes/{id}/returns": {
      "post": {
        "operationId": "returnDeliveryNote",
        "summary": "Reso di un DDT gia' fatturato",
        "description": "Il DDT fatturato non si corregge piu' (PATCH 409): il reso arriva con articoli e quantita'. esse24 prende le righe della fattura che vengono da questo DDT e prepara la nota di credito in bozza coi prezzi della fattura; la emette l'amministrazione. Un reso, una nota: un secondo invio con lo stesso reso_id restituisce quella gia' fatta (esito 'gia_fatta') e, se porta 'rimborso', lo aggiorna. L'esito e' sempre nel corpo: 'bozza' (fattura del DDT ancora in bozza, rimandare quando e' emessa) e 'non_fatturata' (DDT non fatturato, si corregge col PATCH) non sono errori.",
        "tags": [
          "Delivery Notes"
        ],
        "security": [
          {
            "ApiKeyAuth": [
              "delivery-notes:write"
            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reso_id",
                  "items"
                ],
                "properties": {
                  "reso_id": {
                    "type": "string",
                    "description": "Id del reso nel sistema mittente: chiave di idempotenza"
                  },
                  "reso_code": {
                    "type": "string"
                  },
                  "reso_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "required": [
                        "item_code",
                        "quantity"
                      ],
                      "properties": {
                        "item_code": {
                          "type": "string"
                        },
                        "quantity": {
                          "type": "number",
                          "exclusiveMinimum": 0
                        }
                      }
                    }
                  },
                  "rimborso": {
                    "type": "object",
                    "description": "Come il valore del reso e' tornato al cliente. Assente = non ancora deciso: rimandare il reso con lo stesso reso_id quando si decide aggiorna il rimborso della nota gia' fatta. Con modo 'buono_usato' esse24, quando nota e fattura della bolla indicata sono emesse, compensa la nota su quella fattura; se la fattura era gia' riscossa per intero (RIMESSA DIRETTA PAGATO) ne storna la parte pagata col buono. Entro 5 centesimi di differenza dalla nota si compensa la nota intera.",
                    "required": [
                      "modo",
                      "importo"
                    ],
                    "properties": {
                      "modo": {
                        "type": "string",
                        "enum": [
                          "buono_usato",
                          "buono_aperto",
                          "contanti",
                          "bonifico",
                          "nessuno"
                        ]
                      },
                      "importo": {
                        "type": "number",
                        "minimum": 0,
                        "description": "Valore restituito, IVA inclusa"
                      },
                      "ddt_id": {
                        "type": "string",
                        "format": "uuid",
                        "description": "Solo buono_usato: external_id della bolla dove il buono e' stato speso. In alternativa a utilizzi."
                      },
                      "utilizzi": {
                        "type": "array",
                        "description": "Solo buono_usato, se il buono e' stato speso su piu' bolle",
                        "items": {
                          "type": "object",
                          "required": [
                            "ddt_id",
                            "importo"
                          ],
                          "properties": {
                            "ddt_id": {
                              "type": "string",
                              "format": "uuid"
                            },
                            "importo": {
                              "type": "number",
                              "minimum": 0
                            }
                          }
                        }
                      },
                      "resto": {
                        "type": "object",
                        "description": "Quello che resta dopo il cambio o l'uso parziale del buono",
                        "required": [
                          "modo",
                          "importo"
                        ],
                        "properties": {
                          "modo": {
                            "type": "string",
                            "enum": [
                              "contanti",
                              "buono_aperto"
                            ]
                          },
                          "importo": {
                            "type": "number",
                            "minimum": 0
                          }
                        }
                      },
                      "data": {
                        "type": "string",
                        "format": "date"
                      }
                    }
                  }
                }
              },
              "example": {
                "reso_id": "a399526d-9c4b-4972-872e-fde9e3a6a498",
                "reso_code": "RES-2026-00374",
                "reso_date": "2026-10-12",
                "items": [
                  {
                    "item_code": "V40HV27F8000",
                    "quantity": 1
                  }
                ],
                "rimborso": {
                  "modo": "buono_usato",
                  "importo": 8.51,
                  "ddt_id": "a1763527-569a-4893-8c42-3cbc0b2f67cd",
                  "resto": {
                    "modo": "contanti",
                    "importo": 0
                  },
                  "data": "2026-10-12"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Nessuna nota nuova: gia_fatta, bozza o non_fatturata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "esito": "gia_fatta",
                    "credit_note_id": "cn-uuid-001",
                    "stato": "issued",
                    "numero": "94/MC",
                    "data": "2026-10-28",
                    "totale": 8.52
                  }
                }
              }
            }
          },
          "201": {
            "description": "Nota di credito creata in bozza",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "esito": "creata",
                    "credit_note_id": "cn-uuid-001",
                    "stato": "draft",
                    "fattura": "7412/M0",
                    "totale": 8.52
                  }
                }
              }
            }
          },
          "400": {
            "description": "Corpo non valido",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "VALIDATION_ERROR",
                    "message": "Field 'rimborso.modo' must be one of: buono_usato, buono_aperto, contanti, bonifico, nessuno."
                  }
                }
              }
            }
          },
          "404": {
            "description": "DDT non trovato",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "NOT_FOUND",
                    "message": "Delivery note 'ddt-uuid-001' not found."
                  }
                }
              }
            }
          },
          "422": {
            "description": "Righe gia' stornate o assenti dalla fattura",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "RETURN_LINES_NOT_FOUND",
                    "message": "Return 'RES-2026-00374': invoice 7412/M0 has no lines left to credit for some items."
                  }
                }
              }
            }
          }
        }
      }
    },
    "/changes": {
      "get": {
        "operationId": "listChanges",
        "summary": "Registro dei cambiamenti",
        "description": "Ogni creazione, modifica o cancellazione di una risorsa, da esse24 o da API, in ordine di commit. Si legge ripartendo da `next_since`: un evento webhook perso si recupera da qui. Il dato attuale si legge con la GET della risorsa. Restituisce solo le risorse per cui la chiave ha lo scope di lettura (`<risorsa>:read`; per `purchase-delivery-notes` è `delivery-notes:read`, per `purchase-invoices` è `purchase-invoices:read`). Una chiamata API che cambia altre risorse oltre a quella scritta (la bolla che aggiorna l'evasione dell'ordine) le registra con `origin` = `esse24`.",
        "tags": [
          "Changes"
        ],
        "security": [
          {
            "ApiKeyAuth": [
              "customers:read"
            ]
          },
          {
            "ApiKeyAuth": [
              "suppliers:read"
            ]
          },
          {
            "ApiKeyAuth": [
              "orders:read"
            ]
          },
          {
            "ApiKeyAuth": [
              "invoices:read"
            ]
          },
          {
            "ApiKeyAuth": [
              "purchase-orders:read"
            ]
          },
          {
            "ApiKeyAuth": [
              "delivery-notes:read"
            ]
          },
          {
            "ApiKeyAuth": [
              "purchase-invoices:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "since",
            "in": "query",
            "description": "Il `next_since` della risposta precedente. Assente: dall'inizio del registro, che tiene 90 giorni.",
            "schema": {
              "type": "string",
              "pattern": "^d+-d+$"
            }
          },
          {
            "name": "resource",
            "in": "query",
            "description": "Risorse separate da virgola. Assente: tutte quelle leggibili dalla chiave.",
            "schema": {
              "type": "string",
              "example": "customers,orders"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 500,
              "minimum": 1,
              "maximum": 1000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Cambiamenti dopo il cursore",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ResourceChange"
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "request_id": {
                          "type": "string"
                        },
                        "next_since": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Cursore da passare come `since` alla prossima chiamata."
                        },
                        "has_more": {
                          "type": "boolean"
                        },
                        "origin": {
                          "type": "string",
                          "description": "Il tuo `origin`: l'id della API key usata."
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "seq": 1844032,
                      "resource": "orders",
                      "resource_id": "3f1c2a9e-6b1d-4c8e-9a51-0d6c1e2f7b10",
                      "op": "changed",
                      "origin": "esse24",
                      "changed_at": "2026-11-09T10:12:03.441Z"
                    },
                    {
                      "seq": 1844035,
                      "resource": "customers",
                      "resource_id": "8a7d0c44-2e1b-4f6a-b3c9-5e4d2a1f0c88",
                      "op": "changed",
                      "origin": "b2c4e6f8-1a3c-4e5a-9b7d-0f2e4c6a8b10",
                      "changed_at": "2026-11-09T10:12:07.902Z"
                    }
                  ],
                  "meta": {
                    "request_id": "req_01",
                    "next_since": "90817263-1844035",
                    "has_more": false,
                    "origin": "b2c4e6f8-1a3c-4e5a-9b7d-0f2e4c6a8b10"
                  }
                }
              }
            }
          },
          "403": {
            "description": "La chiave non ha lo scope di lettura di nessuna risorsa richiesta",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "410": {
            "description": "Cursore più vecchio dei 90 giorni del registro (CURSOR_EXPIRED): rileggere le risorse con le GET di elenco e ripartire senza `since`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Cursore, risorsa o limite non validi",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/pricelists/{id}/rules": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "listPricelistRules",
        "summary": "Regole del listino",
        "tags": [
          "Pricelists"
        ],
        "parameters": [
          {
            "name": "is_active",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Regole",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PricelistRuleResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PaginationMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "rule-uuid-001",
                      "company_id": "company-uuid",
                      "price_list_id": "pl-uuid-002",
                      "scope": "category",
                      "item_id": null,
                      "item_code": null,
                      "brand": null,
                      "category_id": "cat-uuid-010",
                      "category_code": "UTENSILI",
                      "compute": "formula",
                      "base": "cost",
                      "base_price_list_id": null,
                      "base_price_list_code": null,
                      "fixed_price": null,
                      "discount_chain": null,
                      "markup_pct": 30,
                      "round_to": 0.1,
                      "round_mode": "nearest",
                      "surcharge": 0,
                      "min_margin_pct": 15,
                      "max_margin_pct": null,
                      "min_quantity": 0,
                      "valid_from": null,
                      "valid_to": null,
                      "is_active": true,
                      "notes": "Utensili: costo + 30%",
                      "created_at": "2026-11-30T10:00:00.000Z",
                      "updated_at": "2026-11-30T10:00:00.000Z"
                    }
                  ],
                  "meta": {
                    "request_id": "req_rules",
                    "page": 1,
                    "per_page": 20,
                    "total": 1,
                    "total_pages": 1
                  }
                }
              }
            }
          },
          "404": {
            "description": "Errore",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "pricelists:read"
            ]
          }
        ]
      },
      "post": {
        "operationId": "createPricelistRule",
        "summary": "Crea regola",
        "tags": [
          "Pricelists"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePricelistRuleRequest"
              },
              "examples": {
                "ricarico_su_famiglia": {
                  "summary": "Famiglia: costo + 30%, arrotondato a 0,10",
                  "value": {
                    "scope": "category",
                    "category_code": "UTENSILI",
                    "compute": "formula",
                    "base": "cost",
                    "markup_pct": 30,
                    "round_to": 0.1,
                    "min_margin_pct": 15
                  }
                },
                "listino_derivato": {
                  "summary": "Tutto il listino: un altro listino − 12%",
                  "value": {
                    "scope": "all",
                    "compute": "formula",
                    "base": "pricelist",
                    "base_price_list_id": "pl-uuid-001",
                    "markup_pct": -12
                  }
                },
                "scaglione": {
                  "summary": "Da 10 pezzi: 5% in più di sconto",
                  "value": {
                    "scope": "all",
                    "compute": "discount",
                    "base": "list",
                    "discount_chain": [
                      5
                    ],
                    "min_quantity": 10
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Regola creata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PricelistRuleResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "rule-uuid-001",
                    "company_id": "company-uuid",
                    "price_list_id": "pl-uuid-002",
                    "scope": "category",
                    "item_id": null,
                    "item_code": null,
                    "brand": null,
                    "category_id": "cat-uuid-010",
                    "category_code": "UTENSILI",
                    "compute": "formula",
                    "base": "cost",
                    "base_price_list_id": null,
                    "base_price_list_code": null,
                    "fixed_price": null,
                    "discount_chain": null,
                    "markup_pct": 30,
                    "round_to": 0.1,
                    "round_mode": "nearest",
                    "surcharge": 0,
                    "min_margin_pct": 15,
                    "max_margin_pct": null,
                    "min_quantity": 0,
                    "valid_from": null,
                    "valid_to": null,
                    "is_active": true,
                    "notes": "Utensili: costo + 30%",
                    "created_at": "2026-11-30T10:00:00.000Z",
                    "updated_at": "2026-11-30T10:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_rule_new"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Errore",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "pricelists:write"
            ]
          }
        ]
      }
    },
    "/pricelists/{id}/rules/{rule_id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "rule_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "patch": {
        "operationId": "updatePricelistRule",
        "summary": "Modifica regola",
        "tags": [
          "Pricelists"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdatePricelistRuleRequest"
              },
              "example": {
                "markup_pct": 32,
                "valid_from": "2027-01-01"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Regola aggiornata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PricelistRuleResponse"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "rule-uuid-001",
                    "company_id": "company-uuid",
                    "price_list_id": "pl-uuid-002",
                    "scope": "category",
                    "item_id": null,
                    "item_code": null,
                    "brand": null,
                    "category_id": "cat-uuid-010",
                    "category_code": "UTENSILI",
                    "compute": "formula",
                    "base": "cost",
                    "base_price_list_id": null,
                    "base_price_list_code": null,
                    "fixed_price": null,
                    "discount_chain": null,
                    "markup_pct": 30,
                    "round_to": 0.1,
                    "round_mode": "nearest",
                    "surcharge": 0,
                    "min_margin_pct": 15,
                    "max_margin_pct": null,
                    "min_quantity": 0,
                    "valid_from": null,
                    "valid_to": null,
                    "is_active": true,
                    "notes": "Utensili: costo + 30%",
                    "created_at": "2026-11-30T10:00:00.000Z",
                    "updated_at": "2026-11-30T10:00:00.000Z"
                  },
                  "meta": {
                    "request_id": "req_rule_upd"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Errore",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "pricelists:write"
            ]
          }
        ]
      },
      "delete": {
        "operationId": "deletePricelistRule",
        "summary": "Elimina regola",
        "tags": [
          "Pricelists"
        ],
        "responses": {
          "204": {
            "description": "Regola eliminata"
          },
          "404": {
            "description": "Errore",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "pricelists:write"
            ]
          }
        ]
      }
    },
    "/prices/resolve": {
      "post": {
        "operationId": "resolvePrices",
        "summary": "Calcola il prezzo di righe di documento",
        "tags": [
          "Pricelists"
        ],
        "description": "Il prezzo che esse24 metterebbe su ciascuna riga, con lo stesso calcolo dell'app: listini (righe e regole), condizioni del cliente e del gruppo, promozioni. Non scrive niente.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ResolvePricesRequest"
              },
              "example": {
                "partner_type": "customer",
                "partner_id": "customer-uuid-001",
                "date": "2026-12-01",
                "lines": [
                  {
                    "item_code": "F10",
                    "quantity": 12,
                    "line_ref": "riga-1"
                  },
                  {
                    "item_code": "NON-ESISTE",
                    "line_ref": "riga-2"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Una voce per riga, nello stesso ordine",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ResolvedPrice"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/RequestMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "line_ref": "riga-1",
                      "item_id": "item-uuid-001",
                      "item_code": "F10",
                      "found": true,
                      "quantity": 12,
                      "date": "2026-12-01",
                      "unit_price": 8.5,
                      "discount_chain": [
                        {
                          "type": "percent",
                          "value": 5
                        }
                      ],
                      "net_unit_price": 8.075,
                      "currency_code": "EUR",
                      "item_vat_rate": 22,
                      "source": "pricelist_rule",
                      "list_origin": "group",
                      "price_list_id": "pl-uuid-002",
                      "price_list_code": "RIV-26",
                      "price_list_name": "Rivenditori 2026",
                      "rule_id": "rule-uuid-004",
                      "condition_id": null,
                      "condition_label": null,
                      "promo_price_list_id": null,
                      "steps": [
                        {
                          "kind": "list",
                          "applied": true,
                          "origin": "group",
                          "label": "Listino Rivenditori 2026 (gruppo del cliente)",
                          "detail": "Regola «Articolo: prezzo fisso, da 10 pezzi» · Regola «Tutti gli articoli: prezzo del listino con sconto 5%, da 5 pezzi»",
                          "unit_price": 8.5,
                          "discount_chain": [
                            {
                              "type": "percent",
                              "value": 5
                            }
                          ],
                          "net": 8.075,
                          "price_list_id": "pl-uuid-002"
                        },
                        {
                          "kind": "promo",
                          "applied": false,
                          "label": "Promozione Natale",
                          "detail": "Non applicata: il prezzo del cliente è già più basso o uguale",
                          "net": 9,
                          "price_list_id": "pl-uuid-009"
                        }
                      ]
                    },
                    {
                      "line_ref": "riga-2",
                      "item_id": null,
                      "item_code": "NON-ESISTE",
                      "found": false,
                      "reason": "item_not_found"
                    }
                  ],
                  "meta": {
                    "request_id": "req_prices"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Errore",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Errore",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": [
              "pricelists:read"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key come Bearer token. Prefisso `esse24_live_` (prod) o `esse24_test_` (sandbox)."
      }
    },
    "schemas": {
      "AddressObject": {
        "type": "object",
        "description": "Indirizzo strutturato",
        "properties": {
          "street": {
            "type": [
              "string",
              "null"
            ]
          },
          "city": {
            "type": [
              "string",
              "null"
            ]
          },
          "postal_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "province": {
            "type": [
              "string",
              "null"
            ]
          },
          "country": {
            "type": [
              "string",
              "null"
            ],
            "description": "Codice ISO 3166-1 alpha-2 (es. IT, DE, FR)"
          }
        }
      },
      "PaginationMeta": {
        "type": "object",
        "required": [
          "request_id",
          "total",
          "page",
          "per_page",
          "total_pages"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "total": {
            "type": "integer"
          },
          "page": {
            "type": "integer"
          },
          "per_page": {
            "type": "integer"
          },
          "total_pages": {
            "type": "integer"
          }
        }
      },
      "RequestMeta": {
        "type": "object",
        "required": [
          "request_id"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "request_id"
            ],
            "properties": {
              "code": {
                "type": "string",
                "example": "NOT_FOUND"
              },
              "message": {
                "type": "string"
              },
              "request_id": {
                "type": "string",
                "format": "uuid"
              },
              "docs_url": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      },
      "InvoiceResponse": {
        "type": "object",
        "description": "Fattura di vendita (con righe — presente solo in GET /{id})",
        "required": [
          "id",
          "company_id",
          "customer_id",
          "invoice_date",
          "status",
          "subtotal",
          "vat_amount",
          "total_amount",
          "document_type",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "invoice_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "invoice_date": {
            "type": "string",
            "format": "date"
          },
          "due_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "confirmed",
              "ready_for_sdi",
              "sent_sdi",
              "delivered",
              "rejected",
              "paid"
            ]
          },
          "subtotal": {
            "type": "number"
          },
          "vat_amount": {
            "type": "number"
          },
          "total_amount": {
            "type": "number"
          },
          "stamp_duty": {
            "type": [
              "number",
              "null"
            ]
          },
          "payment_status": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "unpaid",
              "partial",
              "paid",
              null
            ]
          },
          "paid_amount": {
            "type": [
              "number",
              "null"
            ]
          },
          "payment_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "payment_method": {
            "type": [
              "string",
              "null"
            ]
          },
          "sdi_status": {
            "type": [
              "string",
              "null"
            ]
          },
          "sdi_sent_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "payment_terms": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "document_type": {
            "type": "string",
            "enum": [
              "invoice",
              "credit_note",
              "debit_note",
              "receipt",
              "proforma"
            ],
            "default": "invoice"
          },
          "document_subtype": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "standard",
              "simplified",
              "pa",
              null
            ]
          },
          "posting_status": {
            "type": [
              "string",
              "null"
            ]
          },
          "order_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "L'ordine di vendita chiuso per intero dalla fattura senza bolla (un ordine, una fattura). Le note di credito che stornano quella fattura portano lo stesso order_id: si riconoscono da document_type `credit_note` e original_invoice_id. null se la fattura viene dai DDT (il legame è sulla bolla, `invoice_id`) o è fatta a mano.",
            "example": null
          },
          "created_by": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "items": {
            "type": "array",
            "description": "Righe fattura — presente solo in GET /invoices/{id}",
            "items": {
              "$ref": "#/components/schemas/InvoiceLineItem"
            }
          }
        }
      },
      "InvoiceListItem": {
        "type": "object",
        "description": "Fattura di vendita (senza righe — risposta lista)",
        "required": [
          "id",
          "company_id",
          "customer_id",
          "invoice_date",
          "status",
          "subtotal",
          "vat_amount",
          "total_amount",
          "document_type",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "invoice_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "invoice_date": {
            "type": "string",
            "format": "date"
          },
          "due_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "confirmed",
              "ready_for_sdi",
              "sent_sdi",
              "delivered",
              "rejected",
              "paid"
            ]
          },
          "subtotal": {
            "type": "number"
          },
          "vat_amount": {
            "type": "number"
          },
          "total_amount": {
            "type": "number"
          },
          "stamp_duty": {
            "type": [
              "number",
              "null"
            ]
          },
          "payment_status": {
            "type": [
              "string",
              "null"
            ]
          },
          "paid_amount": {
            "type": [
              "number",
              "null"
            ]
          },
          "payment_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "payment_method": {
            "type": [
              "string",
              "null"
            ]
          },
          "sdi_status": {
            "type": [
              "string",
              "null"
            ]
          },
          "sdi_sent_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "payment_terms": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "document_type": {
            "type": "string"
          },
          "document_subtype": {
            "type": [
              "string",
              "null"
            ]
          },
          "posting_status": {
            "type": [
              "string",
              "null"
            ]
          },
          "order_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "L'ordine di vendita chiuso per intero dalla fattura senza bolla (un ordine, una fattura). Le note di credito che stornano quella fattura portano lo stesso order_id: si riconoscono da document_type `credit_note` e original_invoice_id. null se la fattura viene dai DDT (il legame è sulla bolla, `invoice_id`) o è fatta a mano.",
            "example": null
          },
          "created_by": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "InvoiceLineItem": {
        "type": "object",
        "description": "Riga fattura (sales_invoice_items)",
        "required": [
          "id",
          "invoice_id",
          "line_number",
          "line_type",
          "description",
          "quantity",
          "uom",
          "unit_price",
          "discount_percent",
          "vat_rate",
          "line_total",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "invoice_id": {
            "type": "string",
            "format": "uuid"
          },
          "line_number": {
            "type": "integer"
          },
          "line_type": {
            "type": "string",
            "enum": [
              "item",
              "text",
              "subtotal"
            ],
            "default": "item"
          },
          "item_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "description": {
            "type": "string"
          },
          "quantity": {
            "type": "number"
          },
          "uom": {
            "type": "string",
            "example": "PZ"
          },
          "unit_price": {
            "type": "number"
          },
          "discount_percent": {
            "type": "number",
            "default": 0
          },
          "vat_rate": {
            "type": "number",
            "example": 22
          },
          "line_total": {
            "type": "number"
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateInvoiceRequest": {
        "type": "object",
        "required": [
          "customer_id",
          "invoice_date"
        ],
        "properties": {
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "invoice_date": {
            "type": "string",
            "format": "date",
            "description": "Formato YYYY-MM-DD"
          },
          "invoice_number": {
            "type": "string"
          },
          "due_date": {
            "type": "string",
            "format": "date"
          },
          "document_type": {
            "type": "string",
            "enum": [
              "invoice",
              "credit_note",
              "debit_note",
              "receipt",
              "proforma"
            ],
            "default": "invoice"
          },
          "document_subtype": {
            "type": "string",
            "enum": [
              "standard",
              "simplified",
              "pa"
            ],
            "default": "standard"
          },
          "payment_terms": {
            "type": "string"
          },
          "payment_method": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "external_id": {
            "type": "string",
            "maxLength": 200,
            "description": "La chiave della fattura nel tuo sistema. Un secondo POST con lo stesso valore risponde 409 con existing_id: un retry non crea un secondo documento.",
            "example": "portale-pfa-2026-00412"
          },
          "stamp_duty": {
            "type": "number"
          },
          "section_code": {
            "type": "string",
            "description": "Code of the sales VAT register section that numbers the invoice on issue (e.g. LV2). Omitted: the company default section. Unknown, inactive or not valid for document_type: 422."
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CreateInvoiceLineItem"
            }
          }
        }
      },
      "CreateInvoiceLineItem": {
        "type": "object",
        "required": [
          "description"
        ],
        "properties": {
          "delivery_note_id": {
            "type": "string",
            "format": "uuid",
            "description": "esse24 id of the delivery note this line comes from. The line takes its number and date (DatiDDT), the invoice is linked to it and the delivery note becomes invoiced. Another customer, draft, cancelled, already invoiced or already linked: 422."
          },
          "line_type": {
            "type": "string",
            "enum": [
              "item",
              "text",
              "subtotal"
            ],
            "default": "item"
          },
          "item_code": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "quantity": {
            "type": "number",
            "default": 1,
            "minimum": 0
          },
          "uom": {
            "type": "string",
            "default": "PZ"
          },
          "unit_price": {
            "type": "number",
            "default": 0,
            "minimum": 0
          },
          "discount_percent": {
            "type": "number",
            "default": 0,
            "minimum": 0,
            "maximum": 100
          },
          "vat_rate": {
            "type": "number",
            "default": 22
          },
          "notes": {
            "type": "string"
          }
        }
      },
      "UpdateInvoiceRequest": {
        "type": "object",
        "description": "Aggiornabile solo su fatture in stato draft",
        "properties": {
          "invoice_date": {
            "type": "string",
            "format": "date"
          },
          "due_date": {
            "type": "string",
            "format": "date"
          },
          "payment_terms": {
            "type": "string"
          },
          "payment_method": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "stamp_duty": {
            "type": "number"
          }
        }
      },
      "CustomerResponse": {
        "type": "object",
        "description": "Anagrafica cliente",
        "required": [
          "id",
          "company_id",
          "name",
          "blocked",
          "split_payment",
          "stamp_duty",
          "is_vies_required",
          "blocco_fido",
          "marketing_consent",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "code": {
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "type": "string"
          },
          "vat_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "tax_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "format": "email"
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          },
          "website": {
            "type": [
              "string",
              "null"
            ]
          },
          "pec": {
            "type": [
              "string",
              "null"
            ]
          },
          "sdi_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "sdi_code_foreign": {
            "type": [
              "string",
              "null"
            ]
          },
          "payment_terms": {
            "type": [
              "string",
              "null"
            ]
          },
          "payment_method": {
            "type": [
              "string",
              "null"
            ]
          },
          "credit_limit": {
            "type": [
              "number",
              "null"
            ]
          },
          "blocked": {
            "type": "boolean",
            "default": false
          },
          "category": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "billing_address": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/AddressObject"
              },
              {
                "type": "null"
              }
            ]
          },
          "shipping_address": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/AddressObject"
              },
              {
                "type": "null"
              }
            ]
          },
          "person_type": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "individual",
              "company",
              null
            ]
          },
          "legal_form": {
            "type": [
              "string",
              "null"
            ]
          },
          "fiscal_regime": {
            "type": [
              "string",
              "null"
            ]
          },
          "split_payment": {
            "type": "boolean",
            "default": false
          },
          "stamp_duty": {
            "type": "boolean",
            "default": false
          },
          "rea_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "ateco_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "vat_regime_type": {
            "type": [
              "string",
              "null"
            ]
          },
          "vat_subject_type": {
            "type": [
              "string",
              "null"
            ]
          },
          "vat_exigibility": {
            "type": [
              "string",
              "null"
            ]
          },
          "withholding_tax_rate": {
            "type": [
              "number",
              "null"
            ]
          },
          "withholding_tax_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "vies_registered": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "is_vies_required": {
            "type": "boolean",
            "default": false
          },
          "vies_status": {
            "type": [
              "string",
              "null"
            ]
          },
          "vies_checked_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "default_account_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "default_cost_center_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "default_project_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "customer_status": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "active",
              "inactive",
              "prospect",
              null
            ],
            "default": "active"
          },
          "commercial_area": {
            "type": [
              "string",
              "null"
            ]
          },
          "discount_percent": {
            "type": [
              "number",
              "null"
            ]
          },
          "default_price_list_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "default_agent_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "fido_accordato": {
            "type": [
              "number",
              "null"
            ]
          },
          "blocco_fido": {
            "type": "boolean",
            "default": false
          },
          "marketing_consent": {
            "type": "boolean",
            "default": false
          },
          "privacy_notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "bank_abi": {
            "type": [
              "string",
              "null"
            ],
            "description": "ABI (5 cifre) della banca domiciliataria del cliente, per la Ri.Ba."
          },
          "bank_cab": {
            "type": [
              "string",
              "null"
            ],
            "description": "CAB (5 cifre) dello sportello domiciliatario."
          },
          "bank_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "Nome della banca domiciliataria."
          },
          "bank_iban": {
            "type": [
              "string",
              "null"
            ],
            "description": "IBAN del cliente."
          }
        }
      },
      "CreateCustomerRequest": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "vat_number": {
            "type": "string"
          },
          "tax_code": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string"
          },
          "website": {
            "type": "string"
          },
          "pec": {
            "type": "string"
          },
          "sdi_code": {
            "type": "string"
          },
          "sdi_code_foreign": {
            "type": "string"
          },
          "payment_terms": {
            "type": "string",
            "default": "30gg"
          },
          "payment_method": {
            "type": "string"
          },
          "credit_limit": {
            "type": "number"
          },
          "category": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "billing_address": {
            "$ref": "#/components/schemas/AddressObject"
          },
          "shipping_address": {
            "$ref": "#/components/schemas/AddressObject"
          },
          "person_type": {
            "type": "string",
            "enum": [
              "individual",
              "company"
            ]
          },
          "legal_form": {
            "type": "string"
          },
          "fiscal_regime": {
            "type": "string"
          },
          "split_payment": {
            "type": "boolean",
            "default": false
          },
          "stamp_duty": {
            "type": "boolean",
            "default": false
          },
          "rea_number": {
            "type": "string"
          },
          "ateco_code": {
            "type": "string"
          },
          "vat_regime_type": {
            "type": "string"
          },
          "vat_subject_type": {
            "type": "string"
          },
          "vat_exigibility": {
            "type": "string"
          },
          "withholding_tax_rate": {
            "type": "number"
          },
          "withholding_tax_reason": {
            "type": "string"
          },
          "vies_registered": {
            "type": "boolean"
          },
          "default_account_id": {
            "type": "string",
            "format": "uuid"
          },
          "default_cost_center_id": {
            "type": "string",
            "format": "uuid"
          },
          "default_project_id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_status": {
            "type": "string",
            "enum": [
              "active",
              "inactive",
              "prospect"
            ],
            "default": "active"
          },
          "commercial_area": {
            "type": "string"
          },
          "discount_percent": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "default_price_list_id": {
            "type": "string",
            "format": "uuid"
          },
          "default_agent_id": {
            "type": "string",
            "format": "uuid"
          },
          "fido_accordato": {
            "type": "number"
          },
          "blocco_fido": {
            "type": "boolean",
            "default": false
          },
          "marketing_consent": {
            "type": "boolean",
            "default": false
          },
          "privacy_notes": {
            "type": "string"
          }
        }
      },
      "UpdateCustomerRequest": {
        "type": "object",
        "description": "Tutti i campi opzionali — invia solo quelli da modificare",
        "properties": {
          "name": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "vat_number": {
            "type": "string"
          },
          "tax_code": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string"
          },
          "website": {
            "type": "string"
          },
          "pec": {
            "type": "string"
          },
          "sdi_code": {
            "type": "string"
          },
          "sdi_code_foreign": {
            "type": "string"
          },
          "payment_terms": {
            "type": "string"
          },
          "payment_method": {
            "type": "string"
          },
          "credit_limit": {
            "type": "number"
          },
          "blocked": {
            "type": "boolean"
          },
          "category": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "billing_address": {
            "$ref": "#/components/schemas/AddressObject"
          },
          "shipping_address": {
            "$ref": "#/components/schemas/AddressObject"
          },
          "person_type": {
            "type": "string",
            "enum": [
              "individual",
              "company"
            ]
          },
          "legal_form": {
            "type": "string"
          },
          "fiscal_regime": {
            "type": "string"
          },
          "split_payment": {
            "type": "boolean"
          },
          "stamp_duty": {
            "type": "boolean"
          },
          "rea_number": {
            "type": "string"
          },
          "ateco_code": {
            "type": "string"
          },
          "vat_regime_type": {
            "type": "string"
          },
          "vat_subject_type": {
            "type": "string"
          },
          "vat_exigibility": {
            "type": "string"
          },
          "withholding_tax_rate": {
            "type": "number"
          },
          "withholding_tax_reason": {
            "type": "string"
          },
          "vies_registered": {
            "type": "boolean"
          },
          "default_account_id": {
            "type": "string",
            "format": "uuid"
          },
          "default_cost_center_id": {
            "type": "string",
            "format": "uuid"
          },
          "default_project_id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_status": {
            "type": "string",
            "enum": [
              "active",
              "inactive",
              "prospect"
            ]
          },
          "commercial_area": {
            "type": "string"
          },
          "discount_percent": {
            "type": "number"
          },
          "default_price_list_id": {
            "type": "string",
            "format": "uuid"
          },
          "default_agent_id": {
            "type": "string",
            "format": "uuid"
          },
          "fido_accordato": {
            "type": "number"
          },
          "blocco_fido": {
            "type": "boolean"
          },
          "marketing_consent": {
            "type": "boolean"
          },
          "privacy_notes": {
            "type": "string"
          },
          "bank_iban": {
            "type": [
              "string",
              "null"
            ],
            "description": "IBAN del cliente (controllo mod 97, spazi ammessi). Se italiano, ABI e CAB si ricavano da qui. Un IBAN non valido è un 422."
          },
          "bank_abi": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[0-9]{5}$",
            "description": "ABI della banca domiciliataria, 5 cifre. Con un IBAN italiano deve coincidere con quello dell'IBAN."
          },
          "bank_cab": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[0-9]{5}$",
            "description": "CAB dello sportello, 5 cifre. Con un IBAN italiano deve coincidere con quello dell'IBAN."
          },
          "bank_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "Nome della banca. esse24 tiene quello per esteso degli altri clienti con lo stesso ABI che comincia così (il gestionale precedente tronca a 40 caratteri); se manca e l'ABI cambia, il primo con quell'ABI."
          }
        }
      },
      "SupplierResponse": {
        "type": "object",
        "description": "Anagrafica fornitore",
        "required": [
          "id",
          "company_id",
          "name",
          "blocked",
          "is_critical",
          "split_payment",
          "stamp_duty",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "code": {
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "type": "string"
          },
          "vat_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "tax_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "format": "email"
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          },
          "website": {
            "type": [
              "string",
              "null"
            ]
          },
          "pec": {
            "type": [
              "string",
              "null"
            ]
          },
          "sdi_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "payment_terms": {
            "type": [
              "string",
              "null"
            ]
          },
          "payment_method": {
            "type": [
              "string",
              "null"
            ]
          },
          "blocked": {
            "type": "boolean",
            "default": false
          },
          "is_critical": {
            "type": "boolean",
            "default": false
          },
          "category": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "billing_address": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/AddressObject"
              },
              {
                "type": "null"
              }
            ]
          },
          "person_type": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "individual",
              "company",
              null
            ]
          },
          "legal_form": {
            "type": [
              "string",
              "null"
            ]
          },
          "fiscal_regime": {
            "type": [
              "string",
              "null"
            ]
          },
          "split_payment": {
            "type": "boolean",
            "default": false
          },
          "stamp_duty": {
            "type": "boolean",
            "default": false
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateSupplierRequest": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "vat_number": {
            "type": "string"
          },
          "tax_code": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string"
          },
          "website": {
            "type": "string"
          },
          "pec": {
            "type": "string"
          },
          "sdi_code": {
            "type": "string"
          },
          "payment_terms": {
            "type": "string",
            "default": "immediate"
          },
          "payment_method": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "billing_address": {
            "$ref": "#/components/schemas/AddressObject"
          },
          "person_type": {
            "type": "string",
            "enum": [
              "individual",
              "company"
            ]
          },
          "legal_form": {
            "type": "string"
          },
          "fiscal_regime": {
            "type": "string"
          },
          "split_payment": {
            "type": "boolean",
            "default": false
          },
          "stamp_duty": {
            "type": "boolean",
            "default": false
          },
          "is_critical": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "UpdateSupplierRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "vat_number": {
            "type": "string"
          },
          "tax_code": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string"
          },
          "website": {
            "type": "string"
          },
          "pec": {
            "type": "string"
          },
          "sdi_code": {
            "type": "string"
          },
          "payment_terms": {
            "type": "string"
          },
          "payment_method": {
            "type": "string"
          },
          "blocked": {
            "type": "boolean"
          },
          "is_critical": {
            "type": "boolean"
          },
          "category": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "billing_address": {
            "$ref": "#/components/schemas/AddressObject"
          },
          "person_type": {
            "type": "string",
            "enum": [
              "individual",
              "company"
            ]
          },
          "legal_form": {
            "type": "string"
          },
          "fiscal_regime": {
            "type": "string"
          },
          "split_payment": {
            "type": "boolean"
          },
          "stamp_duty": {
            "type": "boolean"
          }
        }
      },
      "BankAccountResponse": {
        "type": "object",
        "description": "Conto bancario",
        "required": [
          "id",
          "company_id",
          "name",
          "account_type",
          "currency",
          "current_balance",
          "is_active",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "display_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "account_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "iban": {
            "type": [
              "string",
              "null"
            ]
          },
          "bic": {
            "type": [
              "string",
              "null"
            ]
          },
          "bank_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "account_type": {
            "type": "string",
            "enum": [
              "checking",
              "savings",
              "credit",
              "cash"
            ]
          },
          "currency": {
            "type": "string",
            "example": "EUR"
          },
          "current_balance": {
            "type": "number"
          },
          "available_balance": {
            "type": [
              "number",
              "null"
            ]
          },
          "is_active": {
            "type": "boolean"
          },
          "last_sync_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "BankTransactionResponse": {
        "type": "object",
        "description": "Movimento bancario",
        "required": [
          "id",
          "company_id",
          "account_id",
          "transaction_date",
          "amount",
          "currency",
          "description",
          "transaction_type",
          "reconciliation_status",
          "is_pending",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "account_id": {
            "type": "string",
            "format": "uuid"
          },
          "transaction_date": {
            "type": "string",
            "format": "date"
          },
          "value_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "amount": {
            "type": "number",
            "description": "Positivo = entrata (credit), negativo = uscita (debit)"
          },
          "currency": {
            "type": "string",
            "example": "EUR"
          },
          "description": {
            "type": "string"
          },
          "counterparty_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "counterparty_iban": {
            "type": [
              "string",
              "null"
            ]
          },
          "reference": {
            "type": [
              "string",
              "null"
            ]
          },
          "reconciliation_status": {
            "type": "string",
            "enum": [
              "unmatched",
              "matched",
              "excluded"
            ]
          },
          "matched_invoice_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "transaction_type": {
            "type": "string",
            "enum": [
              "credit",
              "debit"
            ]
          },
          "is_pending": {
            "type": "boolean"
          },
          "running_balance": {
            "type": [
              "number",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateBankMovementRequest": {
        "type": "object",
        "required": [
          "account_id",
          "transaction_date",
          "description",
          "amount"
        ],
        "properties": {
          "account_id": {
            "type": "string",
            "format": "uuid"
          },
          "transaction_date": {
            "type": "string",
            "format": "date"
          },
          "value_date": {
            "type": "string",
            "format": "date"
          },
          "amount": {
            "type": "number",
            "description": "Non-zero. Positivo = entrata, negativo = uscita."
          },
          "currency": {
            "type": "string",
            "default": "EUR"
          },
          "description": {
            "type": "string"
          },
          "counterparty_name": {
            "type": "string"
          },
          "counterparty_iban": {
            "type": "string"
          },
          "reference": {
            "type": "string"
          },
          "external_id": {
            "type": "string",
            "maxLength": 200,
            "description": "Your id for this movement. Optional. When sent, a second POST with the same external_id on the same account answers 409 instead of creating a duplicate, so a retry is safe. Without it every POST creates a new movement."
          }
        }
      },
      "ItemResponse": {
        "type": "object",
        "description": "Articolo o servizio del catalogo",
        "required": [
          "id",
          "company_id",
          "code",
          "name",
          "unit_of_measure",
          "unit_price",
          "vat_rate",
          "is_active",
          "is_reverse_charge",
          "is_split_payment",
          "stamp_duty_applicable",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "type": {
            "type": "string",
            "enum": [
              "product",
              "service",
              "expense"
            ],
            "default": "product"
          },
          "category": {
            "type": [
              "string",
              "null"
            ]
          },
          "sku": {
            "type": [
              "string",
              "null"
            ]
          },
          "barcode": {
            "type": [
              "string",
              "null"
            ]
          },
          "unit_of_measure": {
            "type": "string",
            "default": "PZ"
          },
          "unit_price": {
            "type": "number"
          },
          "cost_price": {
            "type": [
              "number",
              "null"
            ]
          },
          "vat_rate": {
            "type": "number",
            "default": 22
          },
          "stock_quantity": {
            "type": [
              "number",
              "null"
            ]
          },
          "min_stock_level": {
            "type": [
              "number",
              "null"
            ]
          },
          "is_active": {
            "type": "boolean",
            "default": true
          },
          "brand": {
            "type": [
              "string",
              "null"
            ]
          },
          "model": {
            "type": [
              "string",
              "null"
            ]
          },
          "weight": {
            "type": [
              "number",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "supplier_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "is_cataloged": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "status": {
            "type": [
              "string",
              "null"
            ]
          },
          "tags": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            }
          },
          "vat_nature": {
            "type": [
              "string",
              "null"
            ]
          },
          "is_reverse_charge": {
            "type": "boolean",
            "default": false
          },
          "is_split_payment": {
            "type": "boolean",
            "default": false
          },
          "stamp_duty_applicable": {
            "type": "boolean",
            "default": false
          },
          "reorder_point": {
            "type": [
              "number",
              "null"
            ]
          },
          "lead_time_days": {
            "type": [
              "integer",
              "null"
            ]
          },
          "image_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateItemRequest": {
        "type": "object",
        "required": [
          "code",
          "name"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "product",
              "service",
              "expense"
            ],
            "default": "product"
          },
          "category": {
            "type": "string"
          },
          "sku": {
            "type": "string"
          },
          "barcode": {
            "type": "string"
          },
          "unit_of_measure": {
            "type": "string",
            "default": "PZ"
          },
          "unit_price": {
            "type": "number",
            "default": 0
          },
          "cost_price": {
            "type": "number"
          },
          "vat_rate": {
            "type": "number",
            "default": 22
          },
          "is_active": {
            "type": "boolean",
            "default": true
          },
          "brand": {
            "type": "string"
          },
          "model": {
            "type": "string"
          },
          "weight": {
            "type": "number"
          },
          "notes": {
            "type": "string"
          },
          "supplier_id": {
            "type": "string",
            "format": "uuid"
          },
          "is_cataloged": {
            "type": "boolean"
          },
          "status": {
            "type": "string"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "vat_nature": {
            "type": "string"
          },
          "is_reverse_charge": {
            "type": "boolean",
            "default": false
          },
          "is_split_payment": {
            "type": "boolean",
            "default": false
          },
          "stamp_duty_applicable": {
            "type": "boolean",
            "default": false
          },
          "reorder_point": {
            "type": "number"
          },
          "lead_time_days": {
            "type": "integer"
          },
          "image_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "UpdateItemRequest": {
        "type": "object",
        "description": "Tutti i campi opzionali",
        "properties": {
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "product",
              "service",
              "expense"
            ]
          },
          "category": {
            "type": "string"
          },
          "sku": {
            "type": "string"
          },
          "barcode": {
            "type": "string"
          },
          "unit_of_measure": {
            "type": "string"
          },
          "unit_price": {
            "type": "number"
          },
          "cost_price": {
            "type": "number"
          },
          "vat_rate": {
            "type": "number"
          },
          "is_active": {
            "type": "boolean"
          },
          "brand": {
            "type": "string"
          },
          "model": {
            "type": "string"
          },
          "weight": {
            "type": "number"
          },
          "notes": {
            "type": "string"
          },
          "supplier_id": {
            "type": "string",
            "format": "uuid"
          },
          "is_cataloged": {
            "type": "boolean"
          },
          "status": {
            "type": "string"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "vat_nature": {
            "type": "string"
          },
          "is_reverse_charge": {
            "type": "boolean"
          },
          "is_split_payment": {
            "type": "boolean"
          },
          "stamp_duty_applicable": {
            "type": "boolean"
          },
          "reorder_point": {
            "type": "number"
          },
          "lead_time_days": {
            "type": "integer"
          },
          "image_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "PricelistResponse": {
        "type": "object",
        "description": "Listino prezzi",
        "required": [
          "id",
          "company_id",
          "name",
          "is_default",
          "is_active",
          "is_gross",
          "direction",
          "priority",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "code": {
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "price_list_type": {
            "type": [
              "string",
              "null"
            ]
          },
          "currency_code": {
            "type": [
              "string",
              "null"
            ],
            "default": "EUR"
          },
          "valid_from": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "valid_to": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "is_default": {
            "type": "boolean"
          },
          "is_active": {
            "type": "boolean"
          },
          "is_gross": {
            "type": "boolean"
          },
          "direction": {
            "type": "string",
            "enum": [
              "sales",
              "purchases",
              "both"
            ],
            "description": "Vendita, acquisto o tutti e due. Un listino di acquisto non viene mai scelto in vendita, e viceversa."
          },
          "priority": {
            "type": "integer",
            "default": 0
          },
          "discount_chain": {
            "type": [
              "array",
              "null"
            ],
            "maxItems": 6,
            "items": {
              "type": "object",
              "required": [
                "type",
                "value"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "percent",
                    "markup",
                    "fixed_amount",
                    "markup_amount"
                  ]
                },
                "value": {
                  "type": "number"
                }
              }
            },
            "description": "Sconti in cascata, ognuno sul prezzo già scontato dal precedente."
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "country_codes": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string",
              "pattern": "^[A-Z]{2}$"
            },
            "description": "Paesi (ISO 3166-1 alpha-2) dei clienti a cui il listino vale quando non hanno un listino loro."
          },
          "min_margin_pct": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "exclusiveMaximum": 100,
            "description": "Margine minimo sul costo: sotto, una promozione non si applica e la riga viene segnalata."
          },
          "is_private_default": {
            "type": "boolean",
            "description": "È il listino dei clienti privati (persone fisiche senza partita IVA). Solo lettura: si sceglie nell'app."
          },
          "rule_count": {
            "type": "integer",
            "description": "Solo in GET /pricelists/{id}: quante regole ha il listino."
          }
        }
      },
      "CreatePricelistRequest": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "price_list_type": {
            "type": "string"
          },
          "currency_code": {
            "type": "string",
            "default": "EUR"
          },
          "valid_from": {
            "type": "string",
            "format": "date"
          },
          "valid_to": {
            "type": "string",
            "format": "date"
          },
          "is_default": {
            "type": "boolean",
            "default": false
          },
          "is_active": {
            "type": "boolean",
            "default": true
          },
          "is_gross": {
            "type": "boolean",
            "default": false
          },
          "direction": {
            "type": "string",
            "enum": [
              "sales",
              "purchases",
              "both"
            ],
            "description": "Vendita, acquisto o tutti e due. Un listino di acquisto non viene mai scelto in vendita, e viceversa."
          },
          "priority": {
            "type": "integer",
            "default": 0
          },
          "discount_chain": {
            "type": [
              "array",
              "null"
            ],
            "maxItems": 6,
            "items": {
              "type": "object",
              "required": [
                "type",
                "value"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "percent",
                    "markup",
                    "fixed_amount",
                    "markup_amount"
                  ]
                },
                "value": {
                  "type": "number"
                }
              }
            },
            "description": "Sconti in cascata, ognuno sul prezzo già scontato dal precedente."
          },
          "notes": {
            "type": "string"
          },
          "country_codes": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string",
              "pattern": "^[A-Z]{2}$"
            },
            "description": "Paesi (ISO 3166-1 alpha-2) dei clienti a cui il listino vale quando non hanno un listino loro."
          },
          "min_margin_pct": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "exclusiveMaximum": 100,
            "description": "Margine minimo sul costo: sotto, una promozione non si applica e la riga viene segnalata."
          }
        }
      },
      "UpdatePricelistRequest": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "price_list_type": {
            "type": "string"
          },
          "currency_code": {
            "type": "string"
          },
          "valid_from": {
            "type": "string",
            "format": "date"
          },
          "valid_to": {
            "type": "string",
            "format": "date"
          },
          "is_default": {
            "type": "boolean"
          },
          "is_active": {
            "type": "boolean"
          },
          "is_gross": {
            "type": "boolean"
          },
          "direction": {
            "type": "string",
            "enum": [
              "sales",
              "purchases",
              "both"
            ],
            "description": "Vendita, acquisto o tutti e due. Un listino di acquisto non viene mai scelto in vendita, e viceversa."
          },
          "priority": {
            "type": "integer"
          },
          "discount_chain": {
            "type": [
              "array",
              "null"
            ],
            "maxItems": 6,
            "items": {
              "type": "object",
              "required": [
                "type",
                "value"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "percent",
                    "markup",
                    "fixed_amount",
                    "markup_amount"
                  ]
                },
                "value": {
                  "type": "number"
                }
              }
            },
            "description": "Sconti in cascata, ognuno sul prezzo già scontato dal precedente."
          },
          "notes": {
            "type": "string"
          },
          "country_codes": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string",
              "pattern": "^[A-Z]{2}$"
            },
            "description": "Paesi (ISO 3166-1 alpha-2) dei clienti a cui il listino vale quando non hanno un listino loro."
          },
          "min_margin_pct": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "exclusiveMaximum": 100,
            "description": "Margine minimo sul costo: sotto, una promozione non si applica e la riga viene segnalata."
          }
        }
      },
      "AgentResponse": {
        "type": "object",
        "description": "Agente di vendita",
        "required": [
          "id",
          "company_id",
          "code",
          "name",
          "is_active",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "format": "email"
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          },
          "fiscal_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "vat_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "default_commission_rate": {
            "type": [
              "number",
              "null"
            ]
          },
          "default_commission_base": {
            "type": [
              "string",
              "null"
            ]
          },
          "is_active": {
            "type": "boolean",
            "default": true
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateAgentRequest": {
        "type": "object",
        "required": [
          "code",
          "name"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string"
          },
          "fiscal_code": {
            "type": "string"
          },
          "vat_number": {
            "type": "string"
          },
          "default_commission_rate": {
            "type": "number"
          },
          "default_commission_base": {
            "type": "string"
          },
          "is_active": {
            "type": "boolean",
            "default": true
          },
          "notes": {
            "type": "string"
          }
        }
      },
      "UpdateAgentRequest": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string"
          },
          "fiscal_code": {
            "type": "string"
          },
          "vat_number": {
            "type": "string"
          },
          "default_commission_rate": {
            "type": "number"
          },
          "default_commission_base": {
            "type": "string"
          },
          "is_active": {
            "type": "boolean"
          },
          "notes": {
            "type": "string"
          }
        }
      },
      "WarehouseResponse": {
        "type": "object",
        "description": "Magazzino",
        "required": [
          "id",
          "company_id",
          "code",
          "name",
          "is_active",
          "is_fiscal",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "address": {
            "type": [
              "string",
              "null"
            ]
          },
          "is_active": {
            "type": "boolean"
          },
          "is_fiscal": {
            "type": "boolean"
          },
          "valuation_method": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "fifo",
              "lifo",
              "average",
              null
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateWarehouseRequest": {
        "type": "object",
        "required": [
          "code",
          "name"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "address": {
            "type": "string"
          },
          "is_active": {
            "type": "boolean",
            "default": true
          },
          "is_fiscal": {
            "type": "boolean",
            "default": false
          },
          "valuation_method": {
            "type": "string",
            "enum": [
              "fifo",
              "lifo",
              "average"
            ]
          }
        }
      },
      "UpdateWarehouseRequest": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "address": {
            "type": "string"
          },
          "is_active": {
            "type": "boolean"
          },
          "is_fiscal": {
            "type": "boolean"
          },
          "valuation_method": {
            "type": "string",
            "enum": [
              "fifo",
              "lifo",
              "average"
            ]
          }
        }
      },
      "ChartOfAccountResponse": {
        "type": "object",
        "description": "Voce del piano dei conti",
        "required": [
          "id",
          "company_id",
          "code",
          "name",
          "nature",
          "account_type",
          "level",
          "full_path",
          "allow_direct_posting",
          "vat_managed",
          "is_active",
          "is_locked",
          "opening_balance",
          "debit_movements",
          "credit_movements",
          "closing_balance",
          "movements_count",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "nature": {
            "type": "string",
            "enum": [
              "asset",
              "liability",
              "equity",
              "revenue",
              "expense"
            ]
          },
          "account_type": {
            "type": "string"
          },
          "level": {
            "type": "integer"
          },
          "parent_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "parent_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "full_path": {
            "type": "string"
          },
          "allow_direct_posting": {
            "type": "boolean"
          },
          "vat_managed": {
            "type": "boolean"
          },
          "is_active": {
            "type": "boolean"
          },
          "is_locked": {
            "type": "boolean"
          },
          "opening_balance": {
            "type": "number"
          },
          "debit_movements": {
            "type": "number"
          },
          "credit_movements": {
            "type": "number"
          },
          "closing_balance": {
            "type": "number"
          },
          "movements_count": {
            "type": "integer"
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateChartOfAccountRequest": {
        "type": "object",
        "required": [
          "code",
          "name",
          "nature",
          "account_type"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "nature": {
            "type": "string",
            "enum": [
              "asset",
              "liability",
              "equity",
              "revenue",
              "expense"
            ]
          },
          "account_type": {
            "type": "string"
          },
          "parent_id": {
            "type": "string",
            "format": "uuid"
          },
          "allow_direct_posting": {
            "type": "boolean",
            "default": true
          },
          "vat_managed": {
            "type": "boolean",
            "default": false
          },
          "is_active": {
            "type": "boolean",
            "default": true
          },
          "notes": {
            "type": "string"
          }
        }
      },
      "UpdateChartOfAccountRequest": {
        "type": "object",
        "description": "Aggiornamento bloccato se is_locked=true",
        "properties": {
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "allow_direct_posting": {
            "type": "boolean"
          },
          "vat_managed": {
            "type": "boolean"
          },
          "is_active": {
            "type": "boolean"
          },
          "notes": {
            "type": "string"
          },
          "normal_balance_sign": {
            "type": "string",
            "enum": [
              "debit",
              "credit"
            ]
          }
        }
      },
      "JournalEntryResponse": {
        "type": "object",
        "description": "Scrittura contabile (con righe in GET /{id})",
        "required": [
          "id",
          "company_id",
          "registration_date",
          "description",
          "total_debit",
          "total_credit",
          "status",
          "is_balanced",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "entry_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "registration_date": {
            "type": "string",
            "format": "date"
          },
          "competency_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "document_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "document_type": {
            "type": [
              "string",
              "null"
            ]
          },
          "description": {
            "type": "string"
          },
          "template_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "source_type": {
            "type": [
              "string",
              "null"
            ]
          },
          "source_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "source_document_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "total_debit": {
            "type": "number"
          },
          "total_credit": {
            "type": "number"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "to_consolidate",
              "consolidated",
              "locked"
            ]
          },
          "is_balanced": {
            "type": "boolean"
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_by": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "lines": {
            "type": "array",
            "description": "Righe contabili — presenti solo in GET /{id}",
            "items": {
              "$ref": "#/components/schemas/JournalEntryLine"
            }
          }
        }
      },
      "JournalEntryLine": {
        "type": "object",
        "description": "Riga di scrittura contabile",
        "required": [
          "id",
          "entry_id",
          "line_number",
          "account_id",
          "account_code",
          "account_name",
          "debit_amount",
          "credit_amount",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "entry_id": {
            "type": "string",
            "format": "uuid"
          },
          "line_number": {
            "type": "integer"
          },
          "account_id": {
            "type": "string",
            "format": "uuid"
          },
          "account_code": {
            "type": "string"
          },
          "account_name": {
            "type": "string"
          },
          "debit_amount": {
            "type": "number"
          },
          "credit_amount": {
            "type": "number"
          },
          "cost_center_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "cost_center_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "project_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "project_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "currency_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "exchange_rate": {
            "type": [
              "number",
              "null"
            ]
          },
          "amount_foreign": {
            "type": [
              "number",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateJournalEntryRequest": {
        "type": "object",
        "required": [
          "registration_date",
          "description",
          "lines"
        ],
        "properties": {
          "registration_date": {
            "type": "string",
            "format": "date"
          },
          "competency_date": {
            "type": "string",
            "format": "date"
          },
          "document_number": {
            "type": "string"
          },
          "document_type": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "template_code": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "lines": {
            "type": "array",
            "minItems": 2,
            "items": {
              "$ref": "#/components/schemas/CreateJournalEntryLine"
            }
          }
        }
      },
      "CreateJournalEntryLine": {
        "type": "object",
        "required": [
          "account_id"
        ],
        "properties": {
          "account_id": {
            "type": "string",
            "format": "uuid"
          },
          "debit_amount": {
            "type": "number",
            "minimum": 0,
            "default": 0
          },
          "credit_amount": {
            "type": "number",
            "minimum": 0,
            "default": 0
          },
          "cost_center_id": {
            "type": "string",
            "format": "uuid"
          },
          "project_id": {
            "type": "string",
            "format": "uuid"
          },
          "description": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "currency_code": {
            "type": "string"
          },
          "exchange_rate": {
            "type": "number"
          },
          "amount_foreign": {
            "type": "number"
          }
        }
      },
      "ReceivableInstallmentResponse": {
        "type": "object",
        "description": "Rata di scadenzario (attivo o passivo)",
        "required": [
          "id",
          "installment_number",
          "due_date",
          "due_amount",
          "applied_amount",
          "write_off_amount",
          "status",
          "remaining_amount",
          "type"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "installment_number": {
            "type": "integer"
          },
          "due_date": {
            "type": "string",
            "format": "date"
          },
          "due_amount": {
            "type": "number"
          },
          "applied_amount": {
            "type": "number"
          },
          "write_off_amount": {
            "type": "number"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "partial",
              "paid",
              "overdue",
              "written_off"
            ]
          },
          "paid_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "remaining_amount": {
            "type": "number"
          },
          "type": {
            "type": "string",
            "enum": [
              "receivable",
              "payable"
            ]
          },
          "invoice": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "invoice_number": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "total_amount": {
                "type": "number"
              },
              "status": {
                "type": "string"
              }
            }
          },
          "customer": {
            "type": [
              "object",
              "null"
            ],
            "description": "Presente per receivables",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string"
              },
              "vat_number": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "tax_code": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "supplier": {
            "type": [
              "object",
              "null"
            ],
            "description": "Presente per payables",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string"
              },
              "vat_number": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "tax_code": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        }
      },
      "TrialBalanceResponse": {
        "type": "object",
        "description": "Bilancio di verifica",
        "required": [
          "accounts",
          "meta"
        ],
        "properties": {
          "accounts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TrialBalanceAccount"
            }
          },
          "meta": {
            "type": "object",
            "required": [
              "account_count",
              "total_debit_movements",
              "total_credit_movements",
              "is_balanced"
            ],
            "properties": {
              "account_count": {
                "type": "integer"
              },
              "total_debit_movements": {
                "type": "number"
              },
              "total_credit_movements": {
                "type": "number"
              },
              "is_balanced": {
                "type": "boolean"
              }
            }
          }
        }
      },
      "TrialBalanceAccount": {
        "type": "object",
        "required": [
          "id",
          "code",
          "name",
          "nature",
          "account_type",
          "level",
          "full_path",
          "opening_balance",
          "debit_movements",
          "credit_movements",
          "closing_balance",
          "movements_count",
          "is_active"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "nature": {
            "type": "string"
          },
          "account_type": {
            "type": "string"
          },
          "level": {
            "type": "integer"
          },
          "parent_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "full_path": {
            "type": "string"
          },
          "opening_balance": {
            "type": "number"
          },
          "debit_movements": {
            "type": "number"
          },
          "credit_movements": {
            "type": "number"
          },
          "closing_balance": {
            "type": "number"
          },
          "movements_count": {
            "type": "integer"
          },
          "is_active": {
            "type": "boolean"
          }
        }
      },
      "SalesOrderResponse": {
        "type": "object",
        "description": "Ordine di vendita (con items in GET /{id})",
        "required": [
          "id",
          "company_id",
          "customer_id",
          "order_date",
          "status",
          "subtotal",
          "vat_amount",
          "total_amount",
          "advance_percentage",
          "source",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "order_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "order_date": {
            "type": "string",
            "format": "date"
          },
          "delivery_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "pending",
              "confirmed",
              "partial",
              "fulfilled",
              "invoiced",
              "cancelled"
            ],
            "description": "'partial', 'fulfilled' e 'invoiced' sono scritti da esse24 (evasione e fatturazione) e non sono accettati in scrittura."
          },
          "subtotal": {
            "type": "number",
            "description": "Somma delle righe al netto dello sconto di testata."
          },
          "vat_amount": {
            "type": "number",
            "description": "IVA sull'imponibile scontato: lo sconto di testata la riduce in proporzione."
          },
          "total_amount": {
            "type": "number"
          },
          "payment_terms": {
            "type": [
              "string",
              "null"
            ]
          },
          "delivery_terms": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "internal_notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "fulfillment_progress": {
            "type": [
              "number",
              "null"
            ],
            "description": "Percentuale di evasione calcolata da esse24: il 100 significa nessuna riga con residuo. Non e' scrivibile."
          },
          "quote_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "payment_method": {
            "type": [
              "string",
              "null"
            ]
          },
          "billing_trigger": {
            "type": [
              "string",
              "null"
            ]
          },
          "advance_percentage": {
            "type": "number",
            "default": 0
          },
          "source": {
            "type": "string",
            "default": "api",
            "description": "Origine dell'ordine. Con 'source_external_id' forma l'indice di idempotenza. Il canale 'sales-order.*' e' spento dal 09-11-2026."
          },
          "source_external_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "Chiave del sistema di origine. Filtrabile con match esatto in GET /orders."
          },
          "discount_footer_pct": {
            "type": [
              "number",
              "null"
            ],
            "description": "Sconto di chiusura in percentuale. Se presente e > 0 vince su discount_footer_amount."
          },
          "discount_footer_amount": {
            "type": [
              "number",
              "null"
            ],
            "description": "Sconto di chiusura in valore, usato solo quando discount_footer_pct e' assente o 0."
          },
          "delivery_address": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/AddressObject"
              },
              {
                "type": "null"
              }
            ]
          },
          "cancellation_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "cancelled_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_by": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "items": {
            "type": "array",
            "description": "Righe ordine — presenti in GET /orders/{id}, POST /orders e PATCH /orders/{id}; assenti nella lista",
            "items": {
              "$ref": "#/components/schemas/OrderLineItem"
            }
          }
        }
      },
      "OrderLineItem": {
        "type": "object",
        "description": "Riga ordine di vendita",
        "required": [
          "id",
          "order_id",
          "line_number",
          "line_type",
          "description",
          "quantity",
          "quantity_fulfilled",
          "uom",
          "unit_price",
          "discount_percent",
          "vat_rate",
          "line_total",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "order_id": {
            "type": "string",
            "format": "uuid"
          },
          "line_number": {
            "type": "integer"
          },
          "line_type": {
            "type": "string",
            "enum": [
              "item",
              "text",
              "subtotal"
            ],
            "default": "item"
          },
          "item_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "description": {
            "type": "string"
          },
          "quantity": {
            "type": "number"
          },
          "quantity_fulfilled": {
            "type": "number",
            "default": 0
          },
          "uom": {
            "type": "string",
            "default": "PZ"
          },
          "unit_price": {
            "type": "number"
          },
          "discount_percent": {
            "type": "number",
            "default": 0
          },
          "vat_rate": {
            "type": "number"
          },
          "line_total": {
            "type": "number"
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateOrderRequest": {
        "type": "object",
        "required": [
          "customer_id",
          "order_date",
          "order_number",
          "items"
        ],
        "properties": {
          "customer_id": {
            "type": "string",
            "format": "uuid",
            "description": "UUID esse24 del cliente. Non si aggancia per codice: risolverlo prima con GET /customers?search=<codice> (ilike, verificare il match esatto su 'code') e creare l'anagrafica con POST /customers se assente."
          },
          "order_date": {
            "type": "string",
            "format": "date"
          },
          "order_number": {
            "type": "string",
            "description": "Numero del documento, imposto dal chiamante: per le vendite non esiste un sezionale server-side. Unico per azienda (un doppione risponde 409)."
          },
          "delivery_date": {
            "type": "string",
            "format": "date"
          },
          "payment_terms": {
            "type": "string"
          },
          "delivery_terms": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "internal_notes": {
            "type": "string"
          },
          "payment_method": {
            "type": "string"
          },
          "billing_trigger": {
            "type": "string"
          },
          "advance_percentage": {
            "type": "number",
            "default": 0
          },
          "source": {
            "type": "string",
            "default": "api",
            "description": "Definitivo: non e' modificabile in PATCH. Conviene un valore proprio (il nome del gestionale): entra nell'indice di idempotenza. Il canale 'sales-order.*' e' spento dal 09-11-2026."
          },
          "source_external_id": {
            "type": "string",
            "description": "Chiave stabile del sistema di origine. Unica per (azienda, source): un doppione risponde 409."
          },
          "discount_footer_pct": {
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "description": "Sconto di chiusura in percentuale: applicato ai totali (riduce imponibile e IVA in proporzione)."
          },
          "discount_footer_amount": {
            "type": "number",
            "minimum": 0,
            "description": "Sconto di chiusura in valore: usato solo se discount_footer_pct e' assente o 0."
          },
          "delivery_address": {
            "$ref": "#/components/schemas/AddressObject"
          },
          "quote_id": {
            "type": "string",
            "format": "uuid"
          },
          "items": {
            "type": "array",
            "minItems": 1,
            "items": {
              "$ref": "#/components/schemas/SalesOrderLineInput"
            }
          }
        }
      },
      "CreateOrderLineItem": {
        "type": "object",
        "required": [
          "description",
          "quantity",
          "unit_price"
        ],
        "properties": {
          "line_type": {
            "type": "string",
            "enum": [
              "item",
              "text",
              "subtotal"
            ],
            "default": "item"
          },
          "item_code": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "quantity": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "uom": {
            "type": "string",
            "default": "PZ"
          },
          "unit_price": {
            "type": "number",
            "minimum": 0
          },
          "discount_percent": {
            "type": "number",
            "default": 0
          },
          "vat_rate": {
            "type": "number",
            "default": 22
          },
          "notes": {
            "type": "string"
          }
        }
      },
      "SalesOrderLineInput": {
        "type": "object",
        "description": "Riga di ordine di vendita in input (POST e PATCH). 'line_number' non e' accettato: e' assegnato da esse24, non e' stabile fra un aggiornamento e l'altro e non va usato come chiave di riconciliazione.",
        "required": [
          "description",
          "quantity",
          "unit_price"
        ],
        "properties": {
          "line_type": {
            "type": "string",
            "enum": [
              "item",
              "text",
              "subtotal"
            ],
            "default": "item",
            "description": "Non controllato: una riga 'text' o 'subtotal' viene salvata cosi' com'e', esce nelle GET e nella stampa come riga normale e conta nei totali (quantity x unit_price). Per una nota: quantity 1, unit_price 0."
          },
          "item_code": {
            "type": "string",
            "description": "Codice articolo. E' la chiave del merge selettivo nel PATCH: raccomandato su ogni riga. Una riga senza item_code viene sempre inserita come nuova."
          },
          "description": {
            "type": "string",
            "description": "Obbligatoria per le righe con quantity > 0."
          },
          "quantity": {
            "type": "number",
            "minimum": 0,
            "description": "0 = rimozione della riga nel PATCH (riga scartata nel POST, che ne pretende almeno una > 0). Valori negativi: 422."
          },
          "uom": {
            "type": "string",
            "default": "PZ"
          },
          "unit_price": {
            "type": "number",
            "minimum": 0,
            "description": "Prezzo di listino. Lo sconto va in 'discount_percent', non scontato dentro il prezzo: una catena di sconti moltiplicativi si comprime senza perdite nella percentuale equivalente 1 - PI(1 - si/100)."
          },
          "discount_percent": {
            "type": "number",
            "default": 0,
            "minimum": 0,
            "maximum": 100
          },
          "vat_rate": {
            "type": "number",
            "default": 22
          },
          "notes": {
            "type": "string"
          }
        }
      },
      "UpdateOrderRequest": {
        "type": "object",
        "description": "Aggiornamento dell'ordine di vendita. Non modificabile se annullato o gia' fatturato (409). Con 'items' le righe si allineano per 'item_code' e i totali si ricalcolano: inviare sempre l'intero set.",
        "properties": {
          "customer_id": {
            "type": "string",
            "format": "uuid",
            "description": "Modificabile solo finche' non esiste un DDT non annullato per l'ordine."
          },
          "delivery_date": {
            "type": "string",
            "format": "date"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "pending",
              "confirmed",
              "cancelled"
            ],
            "description": "Transizioni consentite: draft -> pending/confirmed/cancelled, pending -> confirmed/cancelled, confirmed -> cancelled. Gli stati dell'evasione ('partial', 'fulfilled', 'invoiced') li scrive esse24 e sono rifiutati con 422; da quegli stati si puo' solo annullare. Un ordine confermato resta modificabile: se non serve muovere lo stato, non mandarlo."
          },
          "payment_terms": {
            "type": "string"
          },
          "delivery_terms": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "internal_notes": {
            "type": "string"
          },
          "payment_method": {
            "type": "string"
          },
          "billing_trigger": {
            "type": "string"
          },
          "advance_percentage": {
            "type": "number"
          },
          "discount_footer_pct": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "discount_footer_amount": {
            "type": "number",
            "minimum": 0
          },
          "source_external_id": {
            "type": "string",
            "description": "Riscrivibile (utile per agganciare la chiave esterna a un ordine nato prima dell'integrazione). 'source' e 'order_number' invece si fissano alla creazione."
          },
          "delivery_address": {
            "$ref": "#/components/schemas/AddressObject"
          },
          "cancellation_reason": {
            "type": "string",
            "description": "Motivo dell'annullamento. 'cancelled_at' lo scrive esse24 al passaggio di stato."
          },
          "items": {
            "type": "array",
            "minItems": 1,
            "description": "Set completo delle righe. Merge selettivo per 'item_code': le righe impegnate (agganciate a un DDT non annullato per riga o per testata via 'item_code', con quantita' evasa o rifiutata) sono aggiornate in place preservando id e abbinamenti DDT — prezzo, sconto e IVA dal payload, quantita' mai inferiore al consegnato. Le righe libere omesse dal payload vengono rimosse.",
            "items": {
              "$ref": "#/components/schemas/SalesOrderLineInput"
            }
          }
        }
      },
      "QuoteResponse": {
        "type": "object",
        "description": "Preventivo (con items in GET /{id})",
        "required": [
          "id",
          "company_id",
          "customer_id",
          "quote_date",
          "status",
          "subtotal",
          "vat_amount",
          "total_amount",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "quote_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "quote_date": {
            "type": "string",
            "format": "date"
          },
          "valid_until": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "sent",
              "accepted",
              "rejected",
              "expired"
            ]
          },
          "subtotal": {
            "type": "number"
          },
          "vat_amount": {
            "type": "number"
          },
          "total_amount": {
            "type": "number"
          },
          "probability": {
            "type": [
              "number",
              "null"
            ]
          },
          "margin_percentage": {
            "type": [
              "number",
              "null"
            ]
          },
          "payment_terms": {
            "type": [
              "string",
              "null"
            ]
          },
          "delivery_terms": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "order_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "invoice_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "discount_footer_pct": {
            "type": [
              "number",
              "null"
            ]
          },
          "discount_footer_amount": {
            "type": [
              "number",
              "null"
            ]
          },
          "total_discount": {
            "type": [
              "number",
              "null"
            ]
          },
          "created_by": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "items": {
            "type": "array",
            "description": "Righe preventivo — presenti solo in GET /quotes/{id}",
            "items": {
              "$ref": "#/components/schemas/QuoteLineItem"
            }
          }
        }
      },
      "QuoteLineItem": {
        "type": "object",
        "required": [
          "id",
          "quote_id",
          "line_number",
          "line_type",
          "description",
          "quantity",
          "uom",
          "unit_price",
          "discount_percent",
          "vat_rate",
          "line_total",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "quote_id": {
            "type": "string",
            "format": "uuid"
          },
          "line_number": {
            "type": "integer"
          },
          "line_type": {
            "type": "string",
            "enum": [
              "item",
              "text",
              "subtotal"
            ],
            "default": "item"
          },
          "item_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "description": {
            "type": "string"
          },
          "quantity": {
            "type": "number"
          },
          "uom": {
            "type": "string",
            "default": "PZ"
          },
          "unit_price": {
            "type": "number"
          },
          "discount_percent": {
            "type": "number",
            "default": 0
          },
          "vat_rate": {
            "type": "number"
          },
          "line_total": {
            "type": "number"
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateQuoteRequest": {
        "type": "object",
        "required": [
          "customer_id",
          "quote_date",
          "items"
        ],
        "properties": {
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "quote_date": {
            "type": "string",
            "format": "date"
          },
          "valid_until": {
            "type": "string",
            "format": "date"
          },
          "probability": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "payment_terms": {
            "type": "string"
          },
          "delivery_terms": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "discount_footer_pct": {
            "type": "number"
          },
          "discount_footer_amount": {
            "type": "number"
          },
          "items": {
            "type": "array",
            "minItems": 1,
            "items": {
              "$ref": "#/components/schemas/CreateOrderLineItem"
            }
          }
        }
      },
      "UpdateQuoteRequest": {
        "type": "object",
        "properties": {
          "valid_until": {
            "type": "string",
            "format": "date"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "sent",
              "accepted",
              "rejected",
              "expired"
            ]
          },
          "probability": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "payment_terms": {
            "type": "string"
          },
          "delivery_terms": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "discount_footer_pct": {
            "type": "number"
          },
          "discount_footer_amount": {
            "type": "number"
          }
        }
      },
      "PurchaseOrderResponse": {
        "type": "object",
        "description": "Ordine di acquisto (con items in GET /{id})",
        "required": [
          "id",
          "company_id",
          "supplier_id",
          "order_date",
          "status",
          "subtotal",
          "vat_amount",
          "total_amount",
          "advance_percentage",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "supplier_id": {
            "type": "string",
            "format": "uuid"
          },
          "order_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "order_date": {
            "type": "string",
            "format": "date"
          },
          "expected_delivery_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "expected_invoice_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "sent",
              "confirmed",
              "partial",
              "received",
              "cancelled"
            ]
          },
          "subtotal": {
            "type": "number"
          },
          "vat_amount": {
            "type": "number"
          },
          "total_amount": {
            "type": "number"
          },
          "payment_terms": {
            "type": [
              "string",
              "null"
            ]
          },
          "delivery_terms": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "internal_notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "fulfillment_progress": {
            "type": [
              "number",
              "null"
            ]
          },
          "payment_method": {
            "type": [
              "string",
              "null"
            ]
          },
          "billing_trigger": {
            "type": [
              "string",
              "null"
            ]
          },
          "advance_percentage": {
            "type": "number",
            "default": 0
          },
          "external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "cancellation_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "cancelled_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_by": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "items": {
            "type": "array",
            "description": "Righe ordine acquisto — presenti solo in GET /purchase-orders/{id}",
            "items": {
              "$ref": "#/components/schemas/PurchaseOrderLineItem"
            }
          },
          "supplier_confirmation_status": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "awaiting",
              "received",
              "verified",
              "not_required",
              null
            ]
          },
          "supplier_confirmation_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "supplier_confirmation_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "supplier_confirmation_verified_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "prepayment_amount": {
            "type": "number",
            "nullable": true,
            "description": "Prepayment requested before shipment.",
            "example": null
          },
          "prepayment_paid_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "When the prepayment was marked paid."
          },
          "prepayment_paid_note": {
            "type": "string",
            "nullable": true,
            "description": "Note written when the prepayment was marked paid (or unmarked).",
            "example": null
          },
          "prepayment_paid_changed_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Last time the paid flag changed in esse24. Align your own flag only when this is newer than yours."
          },
          "prepayment_receipt_sent_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "When the payment receipt was sent to the supplier."
          },
          "section": {
            "type": "string",
            "nullable": true,
            "description": "Only on GET /purchase-orders/{id}. Suffix of external_id after the last slash (e.g. \"00\", \"MD\"); null when external_id has none.",
            "example": "00"
          }
        }
      },
      "PurchaseOrderLineItem": {
        "type": "object",
        "required": [
          "id",
          "order_id",
          "line_number",
          "line_type",
          "description",
          "quantity",
          "quantity_fulfilled",
          "uom",
          "unit_price",
          "discount_percent",
          "vat_rate",
          "line_total",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "order_id": {
            "type": "string",
            "format": "uuid"
          },
          "line_number": {
            "type": "integer"
          },
          "line_type": {
            "type": "string",
            "enum": [
              "item",
              "text",
              "subtotal"
            ],
            "default": "item"
          },
          "item_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "description": {
            "type": "string"
          },
          "quantity": {
            "type": "number"
          },
          "quantity_fulfilled": {
            "type": "number",
            "default": 0
          },
          "uom": {
            "type": "string",
            "default": "PZ"
          },
          "unit_price": {
            "type": "number"
          },
          "discount_percent": {
            "type": "number",
            "default": 0
          },
          "vat_rate": {
            "type": "number"
          },
          "line_total": {
            "type": "number"
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreatePurchaseOrderRequest": {
        "type": "object",
        "required": [
          "supplier_id",
          "order_date",
          "items"
        ],
        "properties": {
          "supplier_id": {
            "type": "string",
            "format": "uuid"
          },
          "order_date": {
            "type": "string",
            "format": "date"
          },
          "order_number": {
            "type": "string"
          },
          "expected_delivery_date": {
            "type": "string",
            "format": "date"
          },
          "expected_invoice_date": {
            "type": "string",
            "format": "date"
          },
          "payment_terms": {
            "type": "string"
          },
          "delivery_terms": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "internal_notes": {
            "type": "string"
          },
          "payment_method": {
            "type": "string"
          },
          "billing_trigger": {
            "type": "string"
          },
          "advance_percentage": {
            "type": "number",
            "default": 0
          },
          "external_id": {
            "type": "string"
          },
          "items": {
            "type": "array",
            "minItems": 1,
            "description": "Righe dell'ordine. Almeno una riga deve avere quantity > 0: le righe a quantity 0 sono tollerate (l'ERP di origine azzera invece di eliminare) e vengono scartate in creazione.",
            "items": {
              "$ref": "#/components/schemas/PurchaseOrderLineInput"
            }
          },
          "supplier_confirmation": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/SupplierConfirmation"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "UpdatePurchaseOrderRequest": {
        "type": "object",
        "description": "Aggiorna solo i campi presenti nel body; almeno un campo aggiornabile e' richiesto (altrimenti 422). Un ordine `cancelled` e' di norma immodificabile (409), con una sola eccezione: se non ha alcun impegno (nessun DDT non cancellato, nessuna quantita' evasa/inviata/confermata, nessun reso) e il patch non sta a sua volta cancellando, l'ordine viene riportato a `draft` e il patch prosegue. Serve al re-invio dall'ERP dopo un cambio fornitore.",
        "properties": {
          "supplier_id": {
            "type": "string",
            "format": "uuid",
            "description": "Cambio fornitore sull'ordine esistente."
          },
          "expected_delivery_date": {
            "type": "string",
            "format": "date"
          },
          "expected_invoice_date": {
            "type": "string",
            "format": "date"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "sent",
              "confirmed",
              "cancelled"
            ],
            "description": "Transizioni consentite: draft -> draft|sent|confirmed|cancelled; sent -> sent|confirmed|cancelled; confirmed -> confirmed|cancelled. Una transizione non prevista risponde 422."
          },
          "payment_terms": {
            "type": "string"
          },
          "delivery_terms": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "internal_notes": {
            "type": "string"
          },
          "payment_method": {
            "type": "string"
          },
          "billing_trigger": {
            "type": "string"
          },
          "advance_percentage": {
            "type": "number"
          },
          "external_id": {
            "type": "string"
          },
          "items": {
            "type": "array",
            "minItems": 1,
            "description": "Merge selettivo delle righe con chiave item_code (un ERP esterno non conosce gli id riga esse24). NON e' un replace, ma NON e' nemmeno un merge parziale: inviare SEMPRE l'intero set di righe dell'ordine, perche' le righe libere omesse dal payload vengono rimosse. Semantica per riga: (1) riga esistente IMPEGNATA (abbinata a un DDT non cancellato, oppure con quantity_fulfilled/quantity_sent/quantity_confirmed > 0, oppure agganciata a un reso fornitore) non viene mai cancellata; se il suo item_code compare nel payload viene aggiornata in place (id e abbinamenti DDT preservati) con prezzo, sconto e IVA del payload, e quantita' portata al valore inviato ma mai sotto la quantita' gia' ricevuta; (2) riga esistente LIBERA viene riscritta dal payload, e rimossa se il suo item_code non compare; (3) item_code non presente sull'ordine viene inserito in coda; (4) riga del payload con quantity 0 = rimozione della riga (l'ERP di origine azzera invece di eliminare), quantita' negativa = 422. I totali di testata (subtotal, vat_amount, total_amount) sono sempre ricalcolati su tutte le righe risultanti. line_number e' assegnato da esse24 e ignorato se inviato: non e' una chiave di riconciliazione e non e' stabile fra un aggiornamento e l'altro. Se lo stesso item_code compare su piu' righe dello stesso ordine il merge le tratta come una sola: usare un item_code distinto per riga.",
            "items": {
              "$ref": "#/components/schemas/PurchaseOrderLineInput"
            }
          },
          "supplier_confirmation": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/SupplierConfirmation"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "PurchaseOrderLineInput": {
        "type": "object",
        "description": "Riga di ordine di acquisto in input (POST e PATCH). line_number non e' accettato: e' assegnato da esse24.",
        "required": [
          "description",
          "quantity",
          "unit_price"
        ],
        "properties": {
          "line_type": {
            "type": "string",
            "enum": [
              "item",
              "text",
              "subtotal"
            ],
            "default": "item"
          },
          "item_code": {
            "type": "string",
            "description": "Codice articolo. E' la chiave del merge selettivo nel PATCH: raccomandato su ogni riga. Una riga senza item_code viene sempre inserita come nuova."
          },
          "description": {
            "type": "string",
            "description": "Obbligatoria per le righe con quantity > 0."
          },
          "quantity": {
            "type": "number",
            "minimum": 0,
            "description": "0 = rimozione della riga nel PATCH (riga scartata nel POST). Valori negativi: 422."
          },
          "uom": {
            "type": "string",
            "default": "PZ"
          },
          "unit_price": {
            "type": "number",
            "minimum": 0
          },
          "discount_percent": {
            "type": "number",
            "default": 0
          },
          "vat_rate": {
            "type": "number",
            "default": 22
          },
          "notes": {
            "type": "string"
          }
        }
      },
      "StockMovementResponse": {
        "type": "object",
        "description": "Movimento di magazzino (con lines in GET /{id})",
        "required": [
          "id",
          "company_id",
          "warehouse_id",
          "doc_date",
          "doc_type",
          "status",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "warehouse_id": {
            "type": "string",
            "format": "uuid"
          },
          "doc_date": {
            "type": "string",
            "format": "date"
          },
          "doc_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "doc_type": {
            "type": "string",
            "enum": [
              "load",
              "unload",
              "transfer",
              "adjustment"
            ]
          },
          "counterparty_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "reference": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "total_value": {
            "type": [
              "number",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "confirmed",
              "cancelled"
            ]
          },
          "movement_reason_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "source_doc_type": {
            "type": [
              "string",
              "null"
            ]
          },
          "source_doc_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "source_doc_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "lines": {
            "type": "array",
            "description": "Righe movimento — presenti solo in GET /stock-movements/{id}",
            "items": {
              "$ref": "#/components/schemas/StockMovementLine"
            }
          }
        }
      },
      "StockMovementLine": {
        "type": "object",
        "required": [
          "id",
          "movement_id",
          "item_id",
          "item_code",
          "item_name",
          "qty",
          "uom",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "movement_id": {
            "type": "string",
            "format": "uuid"
          },
          "item_id": {
            "type": "string",
            "format": "uuid"
          },
          "item_code": {
            "type": "string"
          },
          "item_name": {
            "type": "string"
          },
          "qty": {
            "type": "number"
          },
          "uom": {
            "type": "string"
          },
          "location_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "lot": {
            "type": [
              "string",
              "null"
            ]
          },
          "serial": {
            "type": [
              "string",
              "null"
            ]
          },
          "unit_cost": {
            "type": [
              "number",
              "null"
            ]
          },
          "total_value": {
            "type": [
              "number",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateStockMovementRequest": {
        "type": "object",
        "required": [
          "warehouse_id",
          "doc_date",
          "doc_type",
          "lines"
        ],
        "properties": {
          "warehouse_id": {
            "type": "string",
            "format": "uuid"
          },
          "doc_date": {
            "type": "string",
            "format": "date"
          },
          "doc_number": {
            "type": "string"
          },
          "doc_type": {
            "type": "string",
            "enum": [
              "load",
              "unload",
              "transfer",
              "adjustment"
            ]
          },
          "counterparty_name": {
            "type": "string"
          },
          "reference": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "movement_reason_id": {
            "type": "string",
            "format": "uuid"
          },
          "source_doc_type": {
            "type": "string"
          },
          "source_doc_id": {
            "type": "string",
            "format": "uuid"
          },
          "source_doc_number": {
            "type": "string"
          },
          "lines": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "required": [
                "item_id",
                "qty"
              ],
              "properties": {
                "item_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "qty": {
                  "type": "number",
                  "exclusiveMinimum": 0
                },
                "uom": {
                  "type": "string"
                },
                "location_name": {
                  "type": "string"
                },
                "lot": {
                  "type": "string"
                },
                "serial": {
                  "type": "string"
                },
                "unit_cost": {
                  "type": "number"
                }
              }
            }
          }
        }
      },
      "CompanyResponse": {
        "type": "object",
        "description": "Dati aziendali (sola lettura)",
        "required": [
          "id",
          "name",
          "currency",
          "electronic_invoicing_enabled",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "vat_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "tax_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "country_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "format": "email"
          },
          "website": {
            "type": [
              "string",
              "null"
            ]
          },
          "address": {
            "type": [
              "string",
              "null"
            ]
          },
          "city": {
            "type": [
              "string",
              "null"
            ]
          },
          "postal_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "province": {
            "type": [
              "string",
              "null"
            ]
          },
          "sdi_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "accounting_method": {
            "type": [
              "string",
              "null"
            ]
          },
          "fiscal_year_start": {
            "type": [
              "string",
              "null"
            ]
          },
          "fiscal_year_end": {
            "type": [
              "string",
              "null"
            ]
          },
          "currency": {
            "type": "string",
            "default": "EUR"
          },
          "electronic_invoicing_enabled": {
            "type": "boolean"
          },
          "electronic_invoicing_channel": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookSubscriptionResponse": {
        "type": "object",
        "description": "Sottoscrizione webhook",
        "required": [
          "id",
          "company_id",
          "api_key_id",
          "name",
          "url",
          "secret_prefix",
          "events",
          "is_active",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "api_key_id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "secret_prefix": {
            "type": "string",
            "description": "Primi 8 caratteri del segreto — per identificazione"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "is_active": {
            "type": "boolean"
          },
          "last_delivery_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_status_code": {
            "type": [
              "integer",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookSubscriptionCreatedResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/WebhookSubscriptionResponse"
          },
          {
            "type": "object",
            "required": [
              "signing_secret"
            ],
            "properties": {
              "signing_secret": {
                "type": "string",
                "description": "Segreto di firma, formato whsec_<hex>. Mostrato una sola volta. Va usato così com'è, prefisso whsec_ compreso, come chiave di HMAC-SHA256 sul corpo grezzo della consegna (header X-Esse24-Signature: sha256=<hex>)."
              }
            }
          }
        ]
      },
      "CreateWebhookSubscriptionRequest": {
        "type": "object",
        "required": [
          "name",
          "url",
          "events"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Deve usare HTTPS. Non sono ammessi indirizzi IP privati o loopback."
          },
          "events": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "enum": [
                "customers.created",
                "customers.updated",
                "customers.deleted",
                "customers.payment_block",
                "suppliers.created",
                "suppliers.updated",
                "invoices.created",
                "invoices.updated",
                "invoices.issued",
                "invoices.deleted",
                "orders.created",
                "orders.updated",
                "quotes.created",
                "quotes.updated",
                "purchase-orders.created",
                "purchase-orders.updated",
                "delivery-notes.created",
                "delivery-notes.updated",
                "sales-delivery-notes.created",
                "sales-delivery-notes.updated",
                "customers.changed",
                "suppliers.changed",
                "suppliers.deleted",
                "orders.changed",
                "orders.deleted",
                "invoices.changed",
                "purchase-orders.changed",
                "purchase-orders.deleted",
                "delivery-notes.changed",
                "delivery-notes.deleted",
                "purchase-delivery-notes.changed",
                "purchase-delivery-notes.deleted",
                "purchase-invoices.changed",
                "purchase-invoices.deleted"
              ]
            },
            "description": "Lista non vuota: [] non è un wildcard (422). Ogni evento richiede lo scope di lettura della sua risorsa (403 INSUFFICIENT_SCOPE). Per una nuova integrazione: <risorsa>.changed / <risorsa>.deleted insieme a GET /v1/changes."
          }
        }
      },
      "UpdateWebhookSubscriptionRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "is_active": {
            "type": "boolean"
          }
        }
      },
      "ReceiptClosureLine": {
        "type": "object",
        "description": "Riga di castelletto della chiusura: un'aliquota, il suo imponibile e la sua imposta.",
        "required": [
          "vat_rate",
          "taxable_amount",
          "vat_amount"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "vat_code": {
            "type": "string",
            "description": "Codice IVA configurato per l'azienda."
          },
          "vat_code_id": {
            "type": "string",
            "format": "uuid"
          },
          "vat_rate": {
            "type": "number",
            "description": "Aliquota in percentuale (es. 22)."
          },
          "taxable_amount": {
            "type": "number",
            "description": "Imponibile, due decimali."
          },
          "vat_amount": {
            "type": "number",
            "description": "Imposta, due decimali."
          },
          "total_amount": {
            "type": "number",
            "readOnly": true
          },
          "vat_register_number": {
            "type": "integer",
            "readOnly": true
          }
        }
      },
      "ReceiptClosureListItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "business_date": {
            "type": "string",
            "format": "date",
            "description": "Giornata di riferimento."
          },
          "rt_serial": {
            "type": "string",
            "description": "Matricola del registratore telematico."
          },
          "z_number": {
            "type": "integer",
            "description": "Progressivo della chiusura Z."
          },
          "source": {
            "type": "string",
            "description": "Origine della registrazione (`api`, `manual`, …)."
          },
          "closed_at": {
            "type": "string",
            "format": "date-time"
          },
          "vat_register_number": {
            "type": "integer"
          },
          "document_number": {
            "type": "string"
          },
          "journal_entry_id": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "settlement_period": {
            "type": "string",
            "description": "Periodo di liquidazione, `YYYY-MM`."
          },
          "taxable_total": {
            "type": "number"
          },
          "vat_total": {
            "type": "number"
          },
          "total_amount": {
            "type": "number"
          },
          "z_total": {
            "type": "number",
            "description": "Totale dichiarato dallo Z: deve quadrare con la somma delle righe."
          },
          "returns_total": {
            "type": "number"
          },
          "voids_total": {
            "type": "number"
          },
          "payment_cash": {
            "type": "number"
          },
          "payment_electronic": {
            "type": "number"
          },
          "payment_unclaimed": {
            "type": "number",
            "description": "Corrispettivi non riscossi."
          },
          "payment_cheque": {
            "type": "number"
          },
          "payment_voucher": {
            "type": "number"
          },
          "payment_rounding": {
            "type": "number",
            "description": "Arrotondamento: non è denaro, è la differenza."
          },
          "warning": {
            "type": "string",
            "nullable": true
          },
          "notes": {
            "type": "string",
            "nullable": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ReceiptClosureResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ReceiptClosureListItem"
          },
          {
            "type": "object",
            "properties": {
              "lines": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ReceiptClosureLine"
                }
              }
            }
          }
        ]
      },
      "CreateReceiptClosureRequest": {
        "type": "object",
        "required": [
          "business_date",
          "rt_serial",
          "z_number",
          "z_total",
          "lines"
        ],
        "properties": {
          "business_date": {
            "type": "string",
            "format": "date"
          },
          "rt_serial": {
            "type": "string",
            "maxLength": 40
          },
          "z_number": {
            "type": "integer",
            "minimum": 1
          },
          "z_total": {
            "type": "number",
            "description": "Totale dello Z. La somma delle righe deve quadrarci, altrimenti 422."
          },
          "lines": {
            "type": "array",
            "minItems": 1,
            "maxItems": 40,
            "items": {
              "$ref": "#/components/schemas/ReceiptClosureLine"
            }
          },
          "returns_total": {
            "type": "number",
            "default": 0
          },
          "voids_total": {
            "type": "number",
            "default": 0
          },
          "payments": {
            "type": "object",
            "description": "Ripartizione degli incassi. La somma dei secchielli più `rounding` deve dare il totale.",
            "properties": {
              "cash": {
                "type": "number"
              },
              "electronic": {
                "type": "number"
              },
              "unclaimed": {
                "type": "number"
              },
              "cheque": {
                "type": "number"
              },
              "voucher": {
                "type": "number"
              },
              "rounding": {
                "type": "number"
              }
            }
          },
          "notes": {
            "type": "string"
          },
          "closed_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateReceiptClosureResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "vat_register_number": {
            "type": "integer",
            "nullable": true,
            "description": "Progressivo del registro IVA corrispettivi. **`null`** quando l'azienda non contabilizza le chiusure di cassa: non viene scritta nessuna riga di registro."
          },
          "document_number": {
            "type": "string",
            "nullable": true,
            "description": "Numero del documento di registro (`COR-AAAA/N`). **`null`** quando l'azienda non contabilizza le chiusure di cassa."
          },
          "business_date": {
            "type": "string",
            "format": "date"
          },
          "rt_serial": {
            "type": "string"
          },
          "z_number": {
            "type": "integer"
          },
          "taxable_total": {
            "type": "number",
            "nullable": true,
            "description": "Imponibile complessivo registrato. **`null`** quando l'azienda non contabilizza le chiusure di cassa: la quadratura col rapporto Z e' stata comunque fatta, ma niente e' finito a registro."
          },
          "vat_total": {
            "type": "number",
            "nullable": true,
            "description": "IVA complessiva registrata. **`null`** quando l'azienda non contabilizza le chiusure di cassa."
          },
          "total_amount": {
            "type": "number"
          },
          "journal_entry_id": {
            "type": "string",
            "format": "uuid",
            "nullable": true,
            "description": "Scrittura in prima nota generata. `null` quando la contabilizzazione e' spenta, o quando l'azienda non contabilizza le chiusure di cassa."
          },
          "warning": {
            "type": "string",
            "nullable": true,
            "description": "Avviso in chiaro quando la chiamata e' riuscita ma non ha prodotto cio' che ci si aspetterebbe: pagamenti ignorati, oppure la chiusura conservata senza registro ne' scrittura."
          },
          "register_row_ids": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Righe di registro create, una per aliquota. Array vuoto quando non se ne scrive nessuna."
          }
        }
      },
      "DeliveryNoteLineItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "delivery_note_id": {
            "type": "string",
            "format": "uuid"
          },
          "line_number": {
            "type": "integer",
            "description": "Assegnato da esse24 nell'ordine di arrivo delle righe."
          },
          "item_code": {
            "type": "string",
            "nullable": true
          },
          "description": {
            "type": "string"
          },
          "quantity": {
            "type": "number"
          },
          "uom": {
            "type": "string",
            "default": "PZ"
          },
          "unit_price": {
            "type": "number"
          },
          "discount_percent": {
            "type": "number"
          },
          "vat_rate": {
            "type": "number"
          },
          "line_total": {
            "type": "number",
            "description": "Imponibile della riga, al NETTO dello sconto di riga e senza IVA. Lo calcola esse24: un line_total nel payload viene ignorato."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "DeliveryNoteLineInput": {
        "type": "object",
        "required": [
          "description",
          "quantity"
        ],
        "properties": {
          "item_code": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "quantity": {
            "type": "number",
            "description": "Maggiore di zero. Una riga a quantity 0 viene scartata senza errore: e' il segnale di rimozione di chi manda lo stesso payload a POST e PATCH."
          },
          "uom": {
            "type": "string",
            "default": "PZ"
          },
          "unit_price": {
            "type": "number",
            "default": 0,
            "description": "Se manca vale 0: la fattura differita copia il prezzo dal DDT, non dall'ordine."
          },
          "discount_percent": {
            "type": "number",
            "default": 0,
            "minimum": 0,
            "maximum": 100
          },
          "vat_rate": {
            "type": "number",
            "default": 22
          },
          "order_number": {
            "type": "string",
            "description": "Numero dell'ordine da cui viene la riga (testo). Serve a stampa e fattura differita («Ns. ordine»); non aggancia la riga all'ordine esse24 e non muove quantity_fulfilled."
          },
          "customer_reference": {
            "type": "string",
            "description": "Riferimento del cliente per la riga («Vs. rif.»), testo."
          },
          "contact_person": {
            "type": "string",
            "description": "Referente per la riga, testo."
          }
        }
      },
      "DeliveryNoteResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "invoice_id": {
            "type": "string",
            "format": "uuid",
            "nullable": true,
            "description": "Valorizzato da esse24 quando il DDT entra in una fattura."
          },
          "ddt_number": {
            "type": "string"
          },
          "issue_date": {
            "type": "string",
            "format": "date"
          },
          "delivery_date": {
            "type": "string",
            "format": "date",
            "nullable": true
          },
          "transport_reason": {
            "type": "string",
            "nullable": true
          },
          "transport_method": {
            "type": "string",
            "nullable": true
          },
          "carrier": {
            "type": "string",
            "nullable": true
          },
          "packages_count": {
            "type": "integer",
            "nullable": true
          },
          "weight": {
            "type": "number",
            "nullable": true
          },
          "appearance": {
            "type": "string",
            "nullable": true
          },
          "delivery_address": {
            "$ref": "#/components/schemas/AddressObject"
          },
          "notes": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "in_transit",
              "delivered",
              "invoiced",
              "cancelled"
            ]
          },
          "billing_status": {
            "type": "string",
            "enum": [
              "unbilled",
              "to_invoice",
              "not_billable",
              "billed"
            ]
          },
          "billed_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "total_amount": {
            "type": "number"
          },
          "order_number": {
            "type": "string",
            "nullable": true
          },
          "job_code": {
            "type": "string",
            "nullable": true
          },
          "external_id": {
            "type": "string",
            "nullable": true,
            "description": "Id del documento nel sistema che l'ha emesso. Unico per azienda."
          },
          "counterparty_kind": {
            "type": "string",
            "enum": [
              "customer"
            ]
          },
          "discount_footer_pct": {
            "type": "number",
            "nullable": true
          },
          "discount_footer_amount": {
            "type": "number",
            "nullable": true
          },
          "inventory_posted_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Resta null sui documenti con external_id: la merce l'ha gia' scaricata chi ha emesso il DDT."
          },
          "customer_reference": {
            "type": "string",
            "nullable": true,
            "description": "Commessa. Chiave di rottura della fatturazione differita."
          },
          "contact_person": {
            "type": "string",
            "nullable": true,
            "description": "Referente. Chiave di rottura della fatturazione differita."
          },
          "destination_ref": {
            "type": "string",
            "nullable": true,
            "description": "Destinazione. Chiave di rottura della fatturazione differita."
          },
          "sede_operativa": {
            "type": "string",
            "nullable": true,
            "description": "Sede che ha emesso il documento: decide il sezionale della fattura differita."
          },
          "order_reference": {
            "type": "string",
            "nullable": true,
            "maxLength": 20,
            "description": "Numero dell'ordine elettronico (NSO/ordine della PA). Finisce in 2.1.2.2 DatiOrdineAcquisto della fattura. Max 20 caratteri."
          },
          "order_date": {
            "type": "string",
            "format": "date",
            "nullable": true,
            "description": "Data dell'ordine elettronico."
          },
          "codice_commessa_convenzione": {
            "type": "string",
            "nullable": true,
            "maxLength": 100,
            "description": "Codice commessa o convenzione (2.1.2.5). Max 100 caratteri."
          },
          "vat_nature": {
            "type": "string",
            "nullable": true,
            "enum": [
              "N1",
              "N2.1",
              "N2.2",
              "N3.1",
              "N3.2",
              "N3.3",
              "N3.4",
              "N3.5",
              "N3.6",
              "N4",
              "N5",
              "N6.1",
              "N6.2",
              "N6.3",
              "N6.4",
              "N6.5",
              "N6.6",
              "N6.7",
              "N6.8",
              "N6.9",
              "N7"
            ],
            "description": "Codice natura FatturaPA dell'operazione (N1–N7), es. N3.2 cessione intracomunitaria, N3.1 esportazione. Assente o stringa vuota = con IVA. La fattura che nasce dal DDT lo eredita in testata; bolle con nature diverse non stanno nella stessa fattura."
          },
          "cig": {
            "type": "string",
            "nullable": true,
            "maxLength": 15,
            "description": "Codice Identificativo Gara (2.1.2.7). Max 15 caratteri. Senza CIG la PA scarta la fattura o non la paga."
          },
          "cup": {
            "type": "string",
            "nullable": true,
            "maxLength": 15,
            "description": "Codice Unico di Progetto (2.1.2.6). Max 15 caratteri."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DeliveryNoteLineItem"
            }
          }
        }
      },
      "CreateDeliveryNoteRequest": {
        "type": "object",
        "required": [
          "customer_id",
          "external_id",
          "ddt_number",
          "issue_date",
          "items"
        ],
        "properties": {
          "customer_id": {
            "type": "string",
            "format": "uuid",
            "description": "UUID esse24 del cliente: si risolve con GET /customers."
          },
          "external_id": {
            "type": "string",
            "description": "Id del documento nel sistema mittente. Obbligatorio: e' cio' che impedisce il doppione quando una richiesta viene ritentata."
          },
          "ddt_number": {
            "type": "string",
            "description": "Numero del DDT nella serie di chi lo emette. Obbligatorio: esse24 non numera i documenti rispecchiati."
          },
          "issue_date": {
            "type": "string",
            "format": "date"
          },
          "delivery_date": {
            "type": "string",
            "format": "date"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "in_transit",
              "delivered"
            ],
            "default": "delivered",
            "description": "'invoiced' lo mette esse24 quando emette la fattura; 'cancelled' si usa solo in PATCH."
          },
          "billing_status": {
            "type": "string",
            "enum": [
              "unbilled",
              "to_invoice",
              "not_billable"
            ],
            "default": "unbilled",
            "description": "'billed' lo mette esse24 quando emette la fattura."
          },
          "transport_reason": {
            "type": "string"
          },
          "transport_method": {
            "type": "string"
          },
          "carrier": {
            "type": "string"
          },
          "packages_count": {
            "type": "integer"
          },
          "weight": {
            "type": "number"
          },
          "appearance": {
            "type": "string"
          },
          "delivery_address": {
            "$ref": "#/components/schemas/AddressObject"
          },
          "notes": {
            "type": "string"
          },
          "order_number": {
            "type": "string"
          },
          "job_code": {
            "type": "string"
          },
          "customer_reference": {
            "type": "string"
          },
          "contact_person": {
            "type": "string"
          },
          "destination_ref": {
            "type": "string"
          },
          "sede_operativa": {
            "type": "string"
          },
          "order_reference": {
            "type": "string",
            "maxLength": 20,
            "description": "Numero dell'ordine elettronico (NSO/ordine della PA). Finisce in 2.1.2.2 DatiOrdineAcquisto della fattura. Max 20 caratteri."
          },
          "order_date": {
            "type": "string",
            "format": "date",
            "description": "Data dell'ordine elettronico."
          },
          "codice_commessa_convenzione": {
            "type": "string",
            "maxLength": 100,
            "description": "Codice commessa o convenzione (2.1.2.5). Max 100 caratteri."
          },
          "vat_nature": {
            "type": "string",
            "enum": [
              "N1",
              "N2.1",
              "N2.2",
              "N3.1",
              "N3.2",
              "N3.3",
              "N3.4",
              "N3.5",
              "N3.6",
              "N4",
              "N5",
              "N6.1",
              "N6.2",
              "N6.3",
              "N6.4",
              "N6.5",
              "N6.6",
              "N6.7",
              "N6.8",
              "N6.9",
              "N7"
            ],
            "description": "Codice natura FatturaPA dell'operazione (N1–N7), es. N3.2 cessione intracomunitaria, N3.1 esportazione. Assente o stringa vuota = con IVA. La fattura che nasce dal DDT lo eredita in testata; bolle con nature diverse non stanno nella stessa fattura."
          },
          "cig": {
            "type": "string",
            "maxLength": 15,
            "description": "Codice Identificativo Gara (2.1.2.7). Max 15 caratteri. Senza CIG la PA scarta la fattura o non la paga."
          },
          "cup": {
            "type": "string",
            "maxLength": 15,
            "description": "Codice Unico di Progetto (2.1.2.6). Max 15 caratteri."
          },
          "discount_footer_pct": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "discount_footer_amount": {
            "type": "number",
            "minimum": 0
          },
          "items": {
            "type": "array",
            "minItems": 1,
            "items": {
              "$ref": "#/components/schemas/DeliveryNoteLineInput"
            }
          }
        }
      },
      "UpdateDeliveryNoteRequest": {
        "type": "object",
        "description": "Fuori di proposito: ddt_number ed external_id (l'identita' del documento si fissa alla creazione), billing_status e invoice_id (li muove la fatturazione di esse24), warehouse_id.",
        "properties": {
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "issue_date": {
            "type": "string",
            "format": "date"
          },
          "delivery_date": {
            "type": "string",
            "format": "date"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "in_transit",
              "delivered",
              "cancelled"
            ],
            "description": "'cancelled' si accetta solo qui: un documento annullato a casa sua deve poterlo diventare anche in esse24, o resta per sempre fra quelli da fatturare. In creazione non e' ammesso — un documento non nasce annullato."
          },
          "transport_reason": {
            "type": "string"
          },
          "transport_method": {
            "type": "string"
          },
          "carrier": {
            "type": "string"
          },
          "packages_count": {
            "type": "integer"
          },
          "weight": {
            "type": "number"
          },
          "appearance": {
            "type": "string"
          },
          "delivery_address": {
            "$ref": "#/components/schemas/AddressObject"
          },
          "notes": {
            "type": "string"
          },
          "order_number": {
            "type": "string"
          },
          "job_code": {
            "type": "string"
          },
          "customer_reference": {
            "type": "string"
          },
          "contact_person": {
            "type": "string"
          },
          "destination_ref": {
            "type": "string"
          },
          "sede_operativa": {
            "type": "string"
          },
          "order_reference": {
            "type": "string",
            "maxLength": 20,
            "description": "Numero dell'ordine elettronico (NSO/ordine della PA). Finisce in 2.1.2.2 DatiOrdineAcquisto della fattura. Max 20 caratteri."
          },
          "order_date": {
            "type": "string",
            "format": "date",
            "description": "Data dell'ordine elettronico."
          },
          "codice_commessa_convenzione": {
            "type": "string",
            "maxLength": 100,
            "description": "Codice commessa o convenzione (2.1.2.5). Max 100 caratteri."
          },
          "vat_nature": {
            "type": "string",
            "enum": [
              "N1",
              "N2.1",
              "N2.2",
              "N3.1",
              "N3.2",
              "N3.3",
              "N3.4",
              "N3.5",
              "N3.6",
              "N4",
              "N5",
              "N6.1",
              "N6.2",
              "N6.3",
              "N6.4",
              "N6.5",
              "N6.6",
              "N6.7",
              "N6.8",
              "N6.9",
              "N7"
            ],
            "description": "Codice natura FatturaPA dell'operazione (N1–N7), es. N3.2 cessione intracomunitaria, N3.1 esportazione. Assente o stringa vuota = con IVA. La fattura che nasce dal DDT lo eredita in testata; bolle con nature diverse non stanno nella stessa fattura."
          },
          "cig": {
            "type": "string",
            "maxLength": 15,
            "description": "Codice Identificativo Gara (2.1.2.7). Max 15 caratteri. Senza CIG la PA scarta la fattura o non la paga."
          },
          "cup": {
            "type": "string",
            "maxLength": 15,
            "description": "Codice Unico di Progetto (2.1.2.6). Max 15 caratteri."
          },
          "discount_footer_pct": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "discount_footer_amount": {
            "type": "number",
            "minimum": 0
          },
          "items": {
            "type": "array",
            "minItems": 1,
            "items": {
              "$ref": "#/components/schemas/DeliveryNoteLineInput"
            },
            "description": "Sostituzione integrale: le righe presenti vengono cancellate e riscritte, e i totali ricalcolati."
          }
        }
      },
      "RegisterPaymentRequest": {
        "type": "object",
        "required": [
          "paid_total"
        ],
        "description": "Il totale incassato finora sulla fattura, non il singolo versamento: viene applicata solo la differenza con quanto gia registrato.",
        "properties": {
          "paid_total": {
            "type": "number",
            "description": "Totale incassato finora su questa fattura (positivo, 2 decimali)",
            "example": 100.77
          },
          "paid_at": {
            "type": "string",
            "format": "date",
            "description": "Data valuta dell incasso (default: oggi)",
            "example": "2026-10-05"
          },
          "payment_method": {
            "type": "string",
            "maxLength": 200,
            "description": "Metodo dell incasso (es. pos, contante). Se l azienda ha una regola per quel metodo la scrittura va sul suo conto (pos sulla banca del POS, contante in cassa), altrimenti sulla banca predefinita. Resta anche nella nota.",
            "example": "contante"
          },
          "notes": {
            "type": "string",
            "maxLength": 200,
            "example": "Incasso in cassa - FT-2026-00001"
          }
        }
      },
      "SupplierConfirmation": {
        "type": "object",
        "description": "La conferma d’ordine del fornitore secondo il sistema che la controlla (es. un PIM). verified e not_required fanno l’ordine confermato (confirmed_progress 100). In PATCH: assente = non toccare, null = svuota.",
        "required": [
          "status"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "awaiting",
              "received",
              "verified",
              "not_required"
            ]
          },
          "number": {
            "type": [
              "string",
              "null"
            ],
            "description": "Numero della conferma del fornitore"
          },
          "date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "Data della conferma del fornitore"
          },
          "verified_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Quando è stata verificata (default: ora della chiamata)"
          }
        }
      },
      "ResourceChange": {
        "type": "object",
        "required": [
          "seq",
          "resource",
          "resource_id",
          "op",
          "origin",
          "changed_at"
        ],
        "properties": {
          "seq": {
            "type": "integer",
            "description": "Crescente. Su eventi dello stesso record, scartare quello con seq minore dell'ultimo applicato."
          },
          "resource": {
            "type": "string",
            "enum": [
              "customers",
              "suppliers",
              "orders",
              "invoices",
              "purchase-orders",
              "delivery-notes",
              "purchase-delivery-notes",
              "purchase-invoices"
            ]
          },
          "resource_id": {
            "type": "string",
            "format": "uuid"
          },
          "op": {
            "type": "string",
            "enum": [
              "changed",
              "deleted"
            ]
          },
          "origin": {
            "type": "string",
            "description": "Id della API key che ha fatto la modifica, oppure `esse24`. Le righe con `origin` uguale a `meta.origin` sono modifiche tue: saltale."
          },
          "changed_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PurchaseDeliveryNoteLineItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "ddt_id": {
            "type": "string",
            "format": "uuid"
          },
          "line_number": {
            "type": "integer"
          },
          "item_code": {
            "type": "string",
            "nullable": true
          },
          "description": {
            "type": "string"
          },
          "quantity": {
            "type": "number"
          },
          "uom": {
            "type": "string"
          },
          "unit_price": {
            "type": "number"
          },
          "discount_percent": {
            "type": "number"
          },
          "vat_rate": {
            "type": "number"
          },
          "line_total": {
            "type": "number",
            "description": "Imponibile della riga (netto IVA): quantity × unit_price × (1 − discount_percent/100), arrotondato al centesimo."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "order_item_code": {
            "type": "string",
            "nullable": true,
            "description": "Only on GET /purchase-delivery-notes/{id}, lines of type item. Code of the matched purchase order line; for an extra line, the code of its twin line; otherwise the code printed on the delivery note.",
            "example": "ART-0042"
          },
          "purchase_order_external_id": {
            "type": "string",
            "nullable": true,
            "description": "Only on GET /purchase-delivery-notes/{id}. external_id of the purchase order of this line (a delivery note can cover several orders).",
            "example": "PO-2026-0412/00"
          },
          "conversion_factor": {
            "type": "number",
            "nullable": true,
            "description": "Only on GET /purchase-delivery-notes/{id}. Our units per supplier unit.",
            "example": 12
          },
          "supplier_uom": {
            "type": "string",
            "nullable": true,
            "description": "Only on GET /purchase-delivery-notes/{id}. Unit printed by the supplier.",
            "example": "CF"
          },
          "supplier_quantity": {
            "type": "number",
            "nullable": true,
            "description": "Only on GET /purchase-delivery-notes/{id}. quantity / conversion_factor, 6 decimals.",
            "example": 2
          }
        }
      },
      "PurchaseDeliveryNoteLineInput": {
        "type": "object",
        "required": [
          "description",
          "quantity"
        ],
        "properties": {
          "item_code": {
            "type": "string"
          },
          "description": {
            "type": "string",
            "minLength": 1
          },
          "quantity": {
            "type": "number",
            "exclusiveMinimum": 0,
            "description": "Deve essere > 0."
          },
          "uom": {
            "type": "string",
            "default": "PZ"
          },
          "unit_price": {
            "type": "number",
            "minimum": 0,
            "default": 0,
            "description": "Prezzo unitario netto IVA."
          },
          "discount_percent": {
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "default": 0
          },
          "vat_rate": {
            "type": "number",
            "default": 22
          }
        }
      },
      "PurchaseDeliveryNoteResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "supplier_id": {
            "type": "string",
            "format": "uuid"
          },
          "ddt_number": {
            "type": "string"
          },
          "issue_date": {
            "type": "string",
            "format": "date"
          },
          "delivery_date": {
            "type": "string",
            "format": "date",
            "nullable": true
          },
          "status": {
            "type": "string",
            "description": "I documenti nati da questa API sono `confirmed`; `received` è lo stato che muove il magazzino (bolle d'arrivo registrate in esse24); `cancelled` annullato."
          },
          "billing_status": {
            "type": "string",
            "description": "Con la causale `reso_a_fornitore` vale `not_billable`."
          },
          "subtotal": {
            "type": "number"
          },
          "vat_amount": {
            "type": "number"
          },
          "total_amount": {
            "type": "number"
          },
          "notes": {
            "type": "string",
            "nullable": true
          },
          "external_id": {
            "type": "string",
            "nullable": true,
            "description": "Id del documento nel sistema mittente. `null` sulle bolle registrate in esse24."
          },
          "transport_cause_id": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "linked_invoice_id": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "origin_ddt_id": {
            "type": "string",
            "format": "uuid",
            "nullable": true,
            "description": "Bolla d'arrivo da cui la merce resa era entrata."
          },
          "return_kind": {
            "type": "string",
            "enum": [
              "credit",
              "replacement",
              "repair"
            ],
            "nullable": true
          },
          "inventory_posted_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "supplier_reference": {
            "type": [
              "string",
              "null"
            ],
            "description": "Riferimento del fornitore (il suo numero di documento), come inviato in POST/PATCH."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "items": {
            "type": "array",
            "description": "Presente nel dettaglio e nelle risposte di scrittura, assente nella lista.",
            "items": {
              "$ref": "#/components/schemas/PurchaseDeliveryNoteLineItem"
            }
          },
          "cancel_reason": {
            "type": "string",
            "nullable": true,
            "description": "Set when status is cancelled. \"relink\": cancelled to redo the links of a supplier invoice; the same document comes back as a new delivery note. Null for any other cancellation.",
            "example": null
          },
          "supplier_name": {
            "type": "string",
            "nullable": true,
            "description": "Only on GET /purchase-delivery-notes/{id}.",
            "example": "Ferramenta Rossi S.r.l."
          },
          "supplier_vat": {
            "type": "string",
            "nullable": true,
            "description": "Only on GET /purchase-delivery-notes/{id}.",
            "example": "IT01234567890"
          },
          "purchase_order_external_id": {
            "type": "string",
            "nullable": true,
            "description": "Only on GET /purchase-delivery-notes/{id}. external_id of the main linked purchase order. Null when not linked, and after cancellation (cancelling unlinks the order).",
            "example": "PO-2026-0412/00"
          },
          "purchase_order_number": {
            "type": "string",
            "nullable": true,
            "description": "Only on GET /purchase-delivery-notes/{id}. Number of the main linked purchase order.",
            "example": "412"
          },
          "invoices": {
            "type": "array",
            "description": "Only on GET /purchase-delivery-notes/{id}. Supplier invoices that bill this delivery note. linked_invoice_id is usually empty: billing is recorded per invoice line.",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "number": {
                  "type": "string",
                  "example": "1287"
                },
                "date": {
                  "type": "string",
                  "format": "date",
                  "example": "2026-10-31"
                }
              }
            }
          }
        }
      },
      "PurchaseInvoiceDeliveryNote": {
        "type": "object",
        "description": "Una bolla d'acquisto che la fattura chiude.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Id di GET /purchase-delivery-notes/{id}."
          },
          "number": {
            "type": "string",
            "description": "Numero esse24 della bolla."
          },
          "date": {
            "type": "string",
            "format": "date"
          },
          "supplier_reference": {
            "type": [
              "string",
              "null"
            ],
            "description": "Il numero stampato sulla bolla del fornitore."
          },
          "external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "billed_amount": {
            "type": [
              "number",
              "null"
            ],
            "description": "Imponibile di questa bolla fatturato da questa fattura (somma delle ripartizioni). Null quando la bolla è agganciata alla fattura senza ripartizioni di riga."
          }
        }
      },
      "PurchaseInvoiceLineItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "line_number": {
            "type": "integer"
          },
          "item_code": {
            "type": [
              "string",
              "null"
            ],
            "description": "Codice stampato in fattura. Le righe di commento non ne hanno."
          },
          "description": {
            "type": "string"
          },
          "quantity": {
            "type": "number"
          },
          "uom": {
            "type": [
              "string",
              "null"
            ],
            "description": "Unità del fornitore."
          },
          "unit_price": {
            "type": "number"
          },
          "discount_percent": {
            "type": [
              "number",
              "null"
            ]
          },
          "vat_rate": {
            "type": [
              "number",
              "null"
            ]
          },
          "line_total": {
            "type": "number",
            "description": "Netto di sconto, prima dell'IVA."
          },
          "ddt_reference": {
            "type": [
              "string",
              "null"
            ],
            "description": "La bolla che il fornitore cita sulla riga."
          },
          "ddt_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "order_reference": {
            "type": [
              "string",
              "null"
            ],
            "description": "L'ordine che il fornitore cita sulla riga."
          },
          "order_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "matched_ddt_line_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "La riga di bolla d'acquisto a cui la riga è abbinata."
          },
          "delivery_note_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "La bolla di quella riga (o della prima ripartizione della riga): uno degli id di `delivery_notes`. Null se la riga non è abbinata."
          },
          "order_line_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "(1.19.1) La riga d'ordine della riga di bolla abbinata. Null se la riga non ha bolla o la riga di bolla non ha la riga d'ordine."
          },
          "order_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "(1.19.1) L'ordine di quella riga."
          },
          "order_number": {
            "type": [
              "string",
              "null"
            ],
            "description": "(1.19.1) Il numero dell'ordine in esse24."
          },
          "order_external_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "(1.19.1) Il riferimento dell'ordine nel gestionale che l'ha mandato (per il portale Renaudo il codice PA-…)."
          },
          "order_line_number": {
            "type": [
              "integer",
              "null"
            ],
            "description": "(1.19.1) Il numero della riga d'ordine."
          },
          "order_line_item_code": {
            "type": [
              "string",
              "null"
            ],
            "description": "(1.19.1) Il codice articolo della riga d'ordine."
          }
        }
      },
      "PurchaseInvoiceResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "supplier_id": {
            "type": "string",
            "format": "uuid"
          },
          "supplier_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "Solo su GET /purchase-invoices/{id}."
          },
          "supplier_vat": {
            "type": [
              "string",
              "null"
            ],
            "description": "Solo su GET /purchase-invoices/{id}."
          },
          "supplier_code": {
            "type": [
              "string",
              "null"
            ],
            "description": "Solo su GET /purchase-invoices/{id}."
          },
          "invoice_number": {
            "type": "string",
            "description": "Come stampato dal fornitore."
          },
          "invoice_date": {
            "type": "string",
            "format": "date"
          },
          "registration_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "received_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "due_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "document_type": {
            "type": "string",
            "description": "Sempre minuscolo, mai null: `invoice` o `credit_note` (alcune aziende hanno anche `autoinvoice_td17`…)."
          },
          "document_subtype": {
            "type": [
              "string",
              "null"
            ],
            "description": "`standard`, `advance`, …"
          },
          "is_autoinvoice": {
            "type": "boolean",
            "description": "True per l'autofattura (TD16–TD19) che esse24 emette per un acquisto estero o in reverse charge: è un documento nostro, non del fornitore. La fattura che integra è `autoinvoice_source_id`."
          },
          "autoinvoice_td_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "autoinvoice_source_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "description": "`draft` = non ancora registrata; `received`, `approved` = registrata."
          },
          "posting_status": {
            "type": [
              "string",
              "null"
            ],
            "description": "Contabilità: `pending`, `posted`, `skipped`, `error`."
          },
          "subtotal": {
            "type": "number",
            "description": "Come scritto sul documento: sulla nota di credito di norma positivo, il segno è in `document_type`."
          },
          "vat_amount": {
            "type": "number"
          },
          "total_amount": {
            "type": "number"
          },
          "payment_status": {
            "type": "string",
            "description": "`unpaid`, `partial`, `paid`, `pending`."
          },
          "paid_amount": {
            "type": "number"
          },
          "payment_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "payment_terms": {
            "type": [
              "string",
              "null"
            ]
          },
          "currency_code": {
            "type": "string"
          },
          "original_invoice_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Sulla nota di credito, la fattura che storna (quando è nota)."
          },
          "origin": {
            "type": [
              "string",
              "null"
            ],
            "description": "Com'è entrata in esse24: `sdi`, `manuale`, `import`, `esse24`."
          },
          "external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "site_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "La sede dell'azienda a cui la fattura è assegnata."
          },
          "site_code": {
            "type": [
              "string",
              "null"
            ],
            "description": "Solo su GET /purchase-invoices/{id}."
          },
          "site_external_codes": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Solo su GET /purchase-invoices/{id}. I codici con cui gli altri sistemi chiamano la sede; vuoto se la fattura non ha sede."
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "delivery_notes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PurchaseInvoiceDeliveryNote"
            },
            "description": "Solo su GET /purchase-invoices/{id}. Le bolle che la fattura chiude, per data e numero."
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PurchaseInvoiceLineItem"
            },
            "description": "Solo su GET /purchase-invoices/{id}. Le righe, per `line_number`."
          }
        }
      },
      "ReceiptDocumentResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "section_id": {
            "type": "string",
            "format": "uuid"
          },
          "fiscal_year": {
            "type": "integer"
          },
          "number": {
            "type": "integer"
          },
          "document_number": {
            "type": "string",
            "description": "Numero e sezionale, es. `1592/SW`."
          },
          "document_date": {
            "type": "string",
            "format": "date"
          },
          "external_id": {
            "type": "string",
            "nullable": true
          },
          "customer_id": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "customer_name": {
            "type": "string",
            "nullable": true
          },
          "delivery_reference": {
            "type": "string",
            "nullable": true
          },
          "order_reference": {
            "type": "string",
            "nullable": true
          },
          "payment_method": {
            "type": "string",
            "nullable": true
          },
          "taxable_total": {
            "type": "number"
          },
          "vat_total": {
            "type": "number"
          },
          "total_amount": {
            "type": "number",
            "description": "Negativo per uno storno."
          },
          "lines": {
            "type": "array",
            "description": "Le righe per aliquota come registrate.",
            "items": {
              "type": "object"
            }
          },
          "vat_register_number": {
            "type": "integer",
            "nullable": true
          },
          "journal_entry_id": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "status": {
            "type": "string",
            "enum": [
              "registered",
              "cancelled"
            ]
          },
          "warning": {
            "type": "string",
            "nullable": true
          },
          "notes": {
            "type": "string",
            "nullable": true
          },
          "items": {
            "type": [
              "array",
              "null"
            ],
            "description": "Le righe articolo inviate in POST, come registrate.",
            "items": {
              "type": "object"
            }
          },
          "reverses_receipt_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Sullo storno: l'id esse24 del documento stornato."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PricelistRuleResponse": {
        "type": "object",
        "description": "Regola con cui un listino calcola i prezzi.",
        "required": [
          "id",
          "price_list_id",
          "scope",
          "compute",
          "base",
          "min_quantity",
          "is_active"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "company_id": {
            "type": "string",
            "format": "uuid"
          },
          "price_list_id": {
            "type": "string",
            "format": "uuid"
          },
          "scope": {
            "type": "string",
            "enum": [
              "item",
              "brand",
              "category",
              "brand_category",
              "all"
            ],
            "description": "Su cosa vale. Vince la più precisa: item > brand_category > brand > category > all."
          },
          "item_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "item_code": {
            "type": [
              "string",
              "null"
            ],
            "description": "In scrittura, al posto di item_id."
          },
          "brand": {
            "type": [
              "string",
              "null"
            ]
          },
          "category_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "category_code": {
            "type": [
              "string",
              "null"
            ],
            "description": "In scrittura, al posto di category_id."
          },
          "compute": {
            "type": "string",
            "enum": [
              "fixed",
              "discount",
              "formula"
            ],
            "description": "fixed: prezzo scritto. discount: prezzo di partenza con sconti che restano sulla riga. formula: partenza ± markup_pct, arrotondata, + surcharge."
          },
          "base": {
            "type": "string",
            "enum": [
              "catalog",
              "cost",
              "pricelist",
              "list"
            ],
            "default": "catalog",
            "description": "Da cosa parte: prezzo dell'articolo, costo, un altro listino (base_price_list_id), o il prezzo che questo listino dà già (uno sconto in più, tipico per quantità)."
          },
          "base_price_list_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "fixed_price": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0
          },
          "discount_chain": {
            "type": [
              "array",
              "null"
            ],
            "maxItems": 6,
            "items": {
              "oneOf": [
                {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "exclusiveMaximum": 100
                },
                {
                  "type": "object",
                  "required": [
                    "type",
                    "value"
                  ],
                  "properties": {
                    "type": {
                      "type": "string",
                      "enum": [
                        "percent",
                        "markup",
                        "fixed_amount",
                        "markup_amount"
                      ]
                    },
                    "value": {
                      "type": "number"
                    }
                  }
                }
              ]
            },
            "description": "In scrittura anche come percentuali semplici: [10, 5] = 10+5%."
          },
          "markup_pct": {
            "type": [
              "number",
              "null"
            ],
            "exclusiveMinimum": -100,
            "description": "Positivo = ricarico, negativo = sconto."
          },
          "round_to": {
            "type": [
              "number",
              "null"
            ],
            "exclusiveMinimum": 0,
            "description": "Arrotonda al multiplo: 0.05, 0.1, 1…"
          },
          "round_mode": {
            "type": "string",
            "enum": [
              "nearest",
              "up",
              "down"
            ],
            "default": "nearest"
          },
          "surcharge": {
            "type": "number",
            "default": 0,
            "description": "Importo aggiunto dopo l'arrotondamento (−0.01 → prezzi che finiscono in ,99)."
          },
          "min_margin_pct": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "exclusiveMaximum": 100
          },
          "max_margin_pct": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "exclusiveMaximum": 100
          },
          "min_quantity": {
            "type": "number",
            "minimum": 0,
            "default": 0,
            "description": "Vale da questa quantità in su: gli scaglioni."
          },
          "valid_from": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "valid_to": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "is_active": {
            "type": "boolean",
            "default": true
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "base_price_list_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreatePricelistRuleRequest": {
        "type": "object",
        "required": [
          "scope",
          "compute"
        ],
        "additionalProperties": false,
        "properties": {
          "scope": {
            "type": "string",
            "enum": [
              "item",
              "brand",
              "category",
              "brand_category",
              "all"
            ],
            "description": "Su cosa vale. Vince la più precisa: item > brand_category > brand > category > all."
          },
          "item_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "item_code": {
            "type": [
              "string",
              "null"
            ],
            "description": "In scrittura, al posto di item_id."
          },
          "brand": {
            "type": [
              "string",
              "null"
            ]
          },
          "category_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "category_code": {
            "type": [
              "string",
              "null"
            ],
            "description": "In scrittura, al posto di category_id."
          },
          "compute": {
            "type": "string",
            "enum": [
              "fixed",
              "discount",
              "formula"
            ],
            "description": "fixed: prezzo scritto. discount: prezzo di partenza con sconti che restano sulla riga. formula: partenza ± markup_pct, arrotondata, + surcharge."
          },
          "base": {
            "type": "string",
            "enum": [
              "catalog",
              "cost",
              "pricelist",
              "list"
            ],
            "default": "catalog",
            "description": "Da cosa parte: prezzo dell'articolo, costo, un altro listino (base_price_list_id), o il prezzo che questo listino dà già (uno sconto in più, tipico per quantità)."
          },
          "base_price_list_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "fixed_price": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0
          },
          "discount_chain": {
            "type": [
              "array",
              "null"
            ],
            "maxItems": 6,
            "items": {
              "oneOf": [
                {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "exclusiveMaximum": 100
                },
                {
                  "type": "object",
                  "required": [
                    "type",
                    "value"
                  ],
                  "properties": {
                    "type": {
                      "type": "string",
                      "enum": [
                        "percent",
                        "markup",
                        "fixed_amount",
                        "markup_amount"
                      ]
                    },
                    "value": {
                      "type": "number"
                    }
                  }
                }
              ]
            },
            "description": "In scrittura anche come percentuali semplici: [10, 5] = 10+5%."
          },
          "markup_pct": {
            "type": [
              "number",
              "null"
            ],
            "exclusiveMinimum": -100,
            "description": "Positivo = ricarico, negativo = sconto."
          },
          "round_to": {
            "type": [
              "number",
              "null"
            ],
            "exclusiveMinimum": 0,
            "description": "Arrotonda al multiplo: 0.05, 0.1, 1…"
          },
          "round_mode": {
            "type": "string",
            "enum": [
              "nearest",
              "up",
              "down"
            ],
            "default": "nearest"
          },
          "surcharge": {
            "type": "number",
            "default": 0,
            "description": "Importo aggiunto dopo l'arrotondamento (−0.01 → prezzi che finiscono in ,99)."
          },
          "min_margin_pct": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "exclusiveMaximum": 100
          },
          "max_margin_pct": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "exclusiveMaximum": 100
          },
          "min_quantity": {
            "type": "number",
            "minimum": 0,
            "default": 0,
            "description": "Vale da questa quantità in su: gli scaglioni."
          },
          "valid_from": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "valid_to": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "is_active": {
            "type": "boolean",
            "default": true
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "UpdatePricelistRuleRequest": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "scope": {
            "type": "string",
            "enum": [
              "item",
              "brand",
              "category",
              "brand_category",
              "all"
            ],
            "description": "Su cosa vale. Vince la più precisa: item > brand_category > brand > category > all."
          },
          "item_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "item_code": {
            "type": [
              "string",
              "null"
            ],
            "description": "In scrittura, al posto di item_id."
          },
          "brand": {
            "type": [
              "string",
              "null"
            ]
          },
          "category_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "category_code": {
            "type": [
              "string",
              "null"
            ],
            "description": "In scrittura, al posto di category_id."
          },
          "compute": {
            "type": "string",
            "enum": [
              "fixed",
              "discount",
              "formula"
            ],
            "description": "fixed: prezzo scritto. discount: prezzo di partenza con sconti che restano sulla riga. formula: partenza ± markup_pct, arrotondata, + surcharge."
          },
          "base": {
            "type": "string",
            "enum": [
              "catalog",
              "cost",
              "pricelist",
              "list"
            ],
            "default": "catalog",
            "description": "Da cosa parte: prezzo dell'articolo, costo, un altro listino (base_price_list_id), o il prezzo che questo listino dà già (uno sconto in più, tipico per quantità)."
          },
          "base_price_list_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "fixed_price": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0
          },
          "discount_chain": {
            "type": [
              "array",
              "null"
            ],
            "maxItems": 6,
            "items": {
              "oneOf": [
                {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "exclusiveMaximum": 100
                },
                {
                  "type": "object",
                  "required": [
                    "type",
                    "value"
                  ],
                  "properties": {
                    "type": {
                      "type": "string",
                      "enum": [
                        "percent",
                        "markup",
                        "fixed_amount",
                        "markup_amount"
                      ]
                    },
                    "value": {
                      "type": "number"
                    }
                  }
                }
              ]
            },
            "description": "In scrittura anche come percentuali semplici: [10, 5] = 10+5%."
          },
          "markup_pct": {
            "type": [
              "number",
              "null"
            ],
            "exclusiveMinimum": -100,
            "description": "Positivo = ricarico, negativo = sconto."
          },
          "round_to": {
            "type": [
              "number",
              "null"
            ],
            "exclusiveMinimum": 0,
            "description": "Arrotonda al multiplo: 0.05, 0.1, 1…"
          },
          "round_mode": {
            "type": "string",
            "enum": [
              "nearest",
              "up",
              "down"
            ],
            "default": "nearest"
          },
          "surcharge": {
            "type": "number",
            "default": 0,
            "description": "Importo aggiunto dopo l'arrotondamento (−0.01 → prezzi che finiscono in ,99)."
          },
          "min_margin_pct": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "exclusiveMaximum": 100
          },
          "max_margin_pct": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "exclusiveMaximum": 100
          },
          "min_quantity": {
            "type": "number",
            "minimum": 0,
            "default": 0,
            "description": "Vale da questa quantità in su: gli scaglioni."
          },
          "valid_from": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "valid_to": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "is_active": {
            "type": "boolean",
            "default": true
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ResolvedPrice": {
        "type": "object",
        "description": "Il prezzo che esse24 metterebbe su una riga di documento.",
        "required": [
          "found"
        ],
        "properties": {
          "line_ref": {
            "type": [
              "string",
              "null"
            ]
          },
          "item_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "item_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "found": {
            "type": "boolean"
          },
          "reason": {
            "type": "string",
            "description": "Solo con found=false, es. item_not_found."
          },
          "quantity": {
            "type": "number"
          },
          "date": {
            "type": "string",
            "format": "date"
          },
          "unit_price": {
            "type": "number",
            "description": "Senza IVA, prima degli sconti di riga."
          },
          "discount_chain": {
            "type": [
              "array",
              "null"
            ],
            "maxItems": 6,
            "items": {
              "type": "object",
              "required": [
                "type",
                "value"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "percent",
                    "markup",
                    "fixed_amount",
                    "markup_amount"
                  ]
                },
                "value": {
                  "type": "number"
                }
              }
            },
            "description": "Sconti in cascata, ognuno sul prezzo già scontato dal precedente."
          },
          "net_unit_price": {
            "type": "number",
            "description": "Senza IVA, dopo gli sconti."
          },
          "currency_code": {
            "type": "string"
          },
          "item_vat_rate": {
            "type": "number"
          },
          "source": {
            "type": "string",
            "enum": [
              "item",
              "customer_price",
              "pricelist_row",
              "pricelist_rule",
              "condition",
              "promo"
            ]
          },
          "list_origin": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "customer_price",
              "assigned",
              "card",
              "group",
              "private",
              "country",
              "default",
              null
            ]
          },
          "price_list_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "price_list_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "price_list_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "rule_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "condition_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "condition_label": {
            "type": [
              "string",
              "null"
            ]
          },
          "promo_price_list_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "margin_pct": {
            "type": [
              "number",
              "null"
            ],
            "description": "Solo con lo scope pricelists:write."
          },
          "below_cost": {
            "type": "boolean",
            "description": "Solo con lo scope pricelists:write."
          },
          "below_min_margin": {
            "type": "boolean",
            "description": "Solo con lo scope pricelists:write."
          },
          "steps": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "enum": [
                    "customer_price",
                    "list",
                    "item",
                    "condition",
                    "promo"
                  ]
                },
                "applied": {
                  "type": "boolean",
                  "description": "false: guardato e scartato (promozione più cara o sotto il margine minimo)."
                },
                "label": {
                  "type": "string"
                },
                "detail": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "description": "La regola in parole. Solo con lo scope pricelists:write: col prezzo accanto dice il costo."
                },
                "unit_price": {
                  "type": [
                    "number",
                    "null"
                  ]
                },
                "discount_chain": {
                  "type": [
                    "array",
                    "null"
                  ],
                  "maxItems": 6,
                  "items": {
                    "type": "object",
                    "required": [
                      "type",
                      "value"
                    ],
                    "properties": {
                      "type": {
                        "type": "string",
                        "enum": [
                          "percent",
                          "markup",
                          "fixed_amount",
                          "markup_amount"
                        ]
                      },
                      "value": {
                        "type": "number"
                      }
                    }
                  },
                  "description": "Sconti in cascata, ognuno sul prezzo già scontato dal precedente."
                },
                "net": {
                  "type": [
                    "number",
                    "null"
                  ]
                },
                "price_list_id": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid"
                },
                "condition_id": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid"
                },
                "origin": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "enum": [
                    "assigned",
                    "card",
                    "group",
                    "private",
                    "country",
                    "default",
                    null
                  ]
                },
                "from_group": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      },
      "ResolvePricesRequest": {
        "type": "object",
        "required": [
          "partner_type",
          "lines"
        ],
        "additionalProperties": false,
        "properties": {
          "partner_type": {
            "type": "string",
            "enum": [
              "customer",
              "supplier"
            ]
          },
          "partner_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Senza: il prezzo per chiunque (listino predefinito, promozioni per tutti)."
          },
          "direction": {
            "type": "string",
            "enum": [
              "sales",
              "purchases"
            ],
            "description": "Default: sales per customer, purchases per supplier."
          },
          "date": {
            "type": "string",
            "format": "date",
            "description": "La data del documento. Default: oggi."
          },
          "lines": {
            "type": "array",
            "minItems": 1,
            "maxItems": 500,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "item_id": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid"
                },
                "item_code": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "quantity": {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "default": 1
                },
                "line_ref": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "description": "Torna com'è nel risultato."
                }
              }
            }
          }
        }
      }
    },
    "parameters": {
      "IdempotencyKeyRequired": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "maxLength": 255
        },
        "description": "Required on this endpoint. A unique value per operation (e.g. a UUID stored with your record), reused on every retry. A retry with the same key returns the first response instead of creating a second document; while the first request is still running it answers 409 IDEMPOTENCY_IN_PROGRESS. Without the header the request is refused with 422 IDEMPOTENCY_KEY_REQUIRED."
      }
    }
  }
}
