{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/officina-it/json-schema/officina-it-invoice-schema.json",
  "title": "Invoice",
  "description": "A workshop invoice. Multi-tenant: belongs to one company.\nCreated from a worksheet; transitions draft → issued via\n`POST /v1/invoices/{id}/issue`.\n",
  "x-generated": "2026-11-19",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/officina-it-openapi.json#/components/schemas/Invoice",
  "type": "object",
  "required": [
    "object",
    "id",
    "work_category_names",
    "status",
    "customer_id",
    "seq_number",
    "payment_method",
    "payment_condition",
    "payment_due_at",
    "vat_exigibility",
    "total_before_tax",
    "total_tax",
    "total_after_tax",
    "total_discount",
    "total_after_discount",
    "total_payments",
    "outstanding_payments",
    "customer_name",
    "created_by_full_name",
    "sdi_status",
    "created_at",
    "updated_at"
  ],
  "properties": {
    "version": {
      "type": "integer",
      "x-since": "2026-10-22",
      "description": "Detail, create and write responses only (lists omit it). Send it\nback as `If-Match` on PATCH (and on the line-items batch): a save\nfrom an older copy is refused with 409. Required from revision\n2026-10-22.\n"
    },
    "object": {
      "type": "string",
      "const": "invoice"
    },
    "id": {
      "type": "string"
    },
    "status": {
      "type": "string",
      "enum": [
        "draft",
        "issued"
      ],
      "description": "Derived from `issued_at`. Soft-deleted invoices 404\nbefore reaching the client — \"deleted\" is never emitted.\n"
    },
    "title": {
      "type": [
        "string",
        "null"
      ]
    },
    "comments": {
      "type": [
        "string",
        "null"
      ]
    },
    "internal_comments": {
      "type": [
        "string",
        "null"
      ]
    },
    "payment_method": {
      "type": "string"
    },
    "payment_condition": {
      "type": "string"
    },
    "payment_due_at": {
      "type": "string",
      "format": "date-time"
    },
    "vat_exigibility": {
      "type": "string"
    },
    "sezionale_id": {
      "type": [
        "string",
        "null"
      ]
    },
    "pa_document_type": {
      "type": [
        "string",
        "null"
      ]
    },
    "pa_document_number": {
      "type": [
        "string",
        "null"
      ]
    },
    "pa_document_date": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "pa_cig": {
      "type": [
        "string",
        "null"
      ]
    },
    "pa_cup": {
      "type": [
        "string",
        "null"
      ]
    },
    "customer_id": {
      "type": "string"
    },
    "vehicle_id": {
      "type": [
        "string",
        "null"
      ]
    },
    "worksheet_id": {
      "type": [
        "string",
        "null"
      ]
    },
    "seq_number": {
      "type": "integer",
      "description": "Per-company monotonic invoice number. 0 on drafts;\nassigned atomically at issuance.\n"
    },
    "total_before_tax": {
      "type": "number",
      "format": "double",
      "description": "Money. Float64 — clients render via the workshop locale\nformatter; avoid arithmetic.\n"
    },
    "total_tax": {
      "type": "number",
      "format": "double"
    },
    "total_after_tax": {
      "type": "number",
      "format": "double"
    },
    "total_discount": {
      "type": "number",
      "format": "double"
    },
    "total_after_discount": {
      "type": "number",
      "format": "double"
    },
    "total_payments": {
      "type": "number",
      "format": "double"
    },
    "outstanding_payments": {
      "type": "number",
      "format": "double"
    },
    "customer_name": {
      "type": "string"
    },
    "vehicle_name": {
      "type": [
        "string",
        "null"
      ]
    },
    "vehicle_license": {
      "type": [
        "string",
        "null"
      ]
    },
    "created_by_full_name": {
      "type": "string"
    },
    "sezionale_code": {
      "type": [
        "string",
        "null"
      ]
    },
    "work_category_name": {
      "type": [
        "string",
        "null"
      ],
      "deprecated": true,
      "description": "The first category's name. Served only to revisions before\n2026-11-02; from 2026-11-02 the key is absent: read\n`work_category_names`.\n"
    },
    "work_category_names": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "x-since": "2026-10-03",
      "description": "Names of the linked worksheet's work categories, in order.\n`[]` when the invoice has no worksheet or the worksheet has\nnone. `work_category_name` (revisions before 2026-11-02) is the first one.\nAvailable since revision 2026-10-03.\n"
    },
    "sdi_status": {
      "type": "string",
      "description": "Italian SDI e-invoice lifecycle status. Empty string\nwhen no e-invoice exists for this invoice. Possible\nnon-empty values: \"sent\", \"rejected\", \"pending_normal\",\n\"pending_warning\", \"pending_late\".\n"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    },
    "issued_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "Populated once the invoice is issued."
    },
    "deleted_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "Soft-deletion timestamp. Populated only on the response\nfrom DELETE /v1/invoices/{id}.\n"
    },
    "line_items": {
      "type": "array",
      "description": "Populated on detail and post-mutation responses. Omitted\nfrom list rows to keep payloads small.\n",
      "items": {
        "$ref": "#/$defs/InvoiceLineItem"
      }
    }
  },
  "$defs": {
    "InvoiceLineItem": {
      "type": "object",
      "required": [
        "object",
        "id",
        "line_type",
        "description",
        "quantity",
        "unit_type",
        "unit_price",
        "unit_discount_rate",
        "tax_rate",
        "total_price",
        "total_before_tax",
        "total_tax",
        "total_after_tax",
        "created_at"
      ],
      "description": "A single row on an invoice. Read-only via this API — line\nitem add/remove is a separate concern not yet exposed on\nthe mobile surface.\n",
      "properties": {
        "object": {
          "type": "string",
          "const": "invoice_line_item"
        },
        "id": {
          "type": "string"
        },
        "line_type": {
          "type": "string",
          "enum": [
            "item",
            "note",
            "separator"
          ],
          "x-since": "2026-10-14",
          "description": "`item` is a priced line. `note` is a description-only line and\n`separator` an empty spacer row: both print without quantity,\nprice and VAT and carry zero amounts (ignore their numeric\nfields). Lines from documents without types report `item`.\n"
        },
        "article_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "work_category_names": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "x-since": "2026-11-02",
          "description": "Lines with an `article_id` only: the article's work categories\n(\"categorie\"), in the order chosen, read from the article now\n(not a snapshot of when the line was written). `[]` when the\narticle has none. The key is absent on lines without an\narticle (free text, notes, separators) and when the article was\ndeleted.\n"
        },
        "article_code": {
          "type": "string",
          "x-since": "2026-11-02",
          "description": "From 2026-11-11: the line's own code (written with it,\nunchanged when the article changes); absent when the line has\nnone and on notes / separators. `description` no longer\ncontains it.\nBefore 2026-11-11: the article's main code as it is now, on lines\nwith an `article_id` whose article still exists and has a code;\nwhen the shop prints codes, a stored code is also put back in\nfront of `description`.\n"
        },
        "description": {
          "type": "string"
        },
        "quantity": {
          "type": "number",
          "format": "double"
        },
        "unit_type": {
          "type": "string"
        },
        "unit_price": {
          "type": "number",
          "format": "double"
        },
        "unit_cost": {
          "type": [
            "number",
            "null"
          ],
          "format": "double"
        },
        "unit_discount_rate": {
          "type": "number",
          "format": "double"
        },
        "tax_rate": {
          "type": "number",
          "format": "double"
        },
        "vat_code": {
          "type": [
            "string",
            "null"
          ]
        },
        "vat_description": {
          "type": [
            "string",
            "null"
          ]
        },
        "total_price": {
          "type": "number",
          "format": "double"
        },
        "total_before_tax": {
          "type": "number",
          "format": "double"
        },
        "total_tax": {
          "type": "number",
          "format": "double"
        },
        "total_after_tax": {
          "type": "number",
          "format": "double"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    }
  }
}