{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/officina-it/json-schema/officina-it-quote-schema.json",
  "title": "Quote",
  "description": "A customer-facing job estimate. Lifecycle: `draft` → `waiting` →\n`accepted` / `rejected` (a draft can also be accepted or rejected\ndirectly; nothing moves a quote back to `draft`). Totals are server-computed from the\nembedded line items and are read-only on the wire.\n",
  "x-generated": "2026-11-19",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/officina-it-openapi.json#/components/schemas/Quote",
  "type": "object",
  "required": [
    "object",
    "id",
    "work_category_ids",
    "work_categories",
    "seq_number",
    "status",
    "customer_id",
    "customer_name",
    "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": "quote"
    },
    "id": {
      "type": "string"
    },
    "seq_number": {
      "type": "integer"
    },
    "status": {
      "type": "string",
      "enum": [
        "draft",
        "waiting",
        "accepted",
        "rejected"
      ],
      "description": "`draft` (revision 2026-10-28): internal, not yet sent to the\ncustomer — every new quote starts here. It becomes `waiting` when\nmarked as sent or when any message about it goes to the customer.\nOlder revisions receive drafts as `waiting`. A `waiting` quote\nwhose `expires_at` has passed and that has no `worksheet_id` is\nclosed as `rejected` by a nightly job (00:15 Rome), on every\nrevision.\n"
    },
    "title": {
      "type": [
        "string",
        "null"
      ]
    },
    "comments": {
      "type": [
        "string",
        "null"
      ]
    },
    "internal_comments": {
      "type": [
        "string",
        "null"
      ]
    },
    "customer_id": {
      "type": "string"
    },
    "customer_name": {
      "type": "string"
    },
    "vehicle_id": {
      "type": [
        "string",
        "null"
      ]
    },
    "vehicle_name": {
      "type": [
        "string",
        "null"
      ]
    },
    "vehicle_license": {
      "type": [
        "string",
        "null"
      ]
    },
    "work_category_id": {
      "type": [
        "string",
        "null"
      ],
      "deprecated": true,
      "description": "The first category's id. Served only to revisions before\n2026-11-02; from 2026-11-02 the key is absent: read\n`work_category_ids`.\n"
    },
    "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_categories`.\n"
    },
    "work_category_ids": {
      "type": "array",
      "items": {
        "type": "string",
        "format": "uuid"
      },
      "x-since": "2026-10-03",
      "description": "Every work category (\"categoria\") of the document, in\nthe order chosen. `work_category_id` (revisions before 2026-11-02)\nalways equals the first. `[]` when the document has none, never\nnull. Available since revision 2026-10-03.\n"
    },
    "work_categories": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/WorkCategory"
      },
      "x-since": "2026-10-03",
      "description": "The same list as `work_category_ids` with each category's\nname, same order. `work_category_name` (revisions before 2026-11-02) is the first one's\nname. Available since revision 2026-10-03.\n"
    },
    "km": {
      "type": [
        "number",
        "null"
      ],
      "format": "double"
    },
    "expires_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date",
      "x-since": "2026-10-27",
      "description": "Data scadenza: the last day the offer is valid (`YYYY-MM-DD`),\nexpired from the next day. `null` = no expiry. Available since\nrevision 2026-10-27.\n"
    },
    "worksheet_id": {
      "type": [
        "string",
        "null"
      ]
    },
    "worksheet_seq_number": {
      "type": [
        "integer",
        "null"
      ]
    },
    "worksheet_created_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "total_before_tax": {
      "type": "number",
      "format": "double"
    },
    "total_tax": {
      "type": "number",
      "format": "double"
    },
    "total_after_tax": {
      "type": "number",
      "format": "double"
    },
    "total_discount": {
      "type": "number",
      "format": "double"
    },
    "total_discount_before_tax": {
      "type": "number",
      "format": "double"
    },
    "total_after_discount": {
      "type": "number",
      "format": "double"
    },
    "total_work": {
      "type": "number",
      "format": "double"
    },
    "total_articles": {
      "type": "number",
      "format": "double"
    },
    "hide_discounts": {
      "type": "boolean"
    },
    "line_items": {
      "type": [
        "array",
        "null"
      ],
      "description": "Embedded line items. Populated on detail / write\nresponses; list responses set this to `null` to keep\npayloads small.\n",
      "items": {
        "$ref": "#/$defs/QuoteLineItem"
      }
    },
    "delivered_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    },
    "archived_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "deleted_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    }
  },
  "$defs": {
    "QuoteLineItem": {
      "type": "object",
      "required": [
        "object",
        "id",
        "line_type",
        "description",
        "unit_type",
        "quantity",
        "unit_price",
        "position",
        "created_at"
      ],
      "properties": {
        "object": {
          "type": "string",
          "const": "quote_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"
        },
        "unit_type": {
          "type": "string"
        },
        "quantity": {
          "type": "number",
          "format": "double"
        },
        "unit_price": {
          "type": "number",
          "format": "double"
        },
        "unit_discount_rate": {
          "type": "number",
          "format": "double"
        },
        "tax_rate": {
          "type": "number",
          "format": "double"
        },
        "vat_code": {
          "type": [
            "string",
            "null"
          ]
        },
        "total_price": {
          "type": "number",
          "format": "double"
        },
        "unit_cost": {
          "type": [
            "number",
            "null"
          ],
          "x-since": "2026-10-15",
          "description": "Internal cost per unit, ex-VAT, never printed on documents. Fixed\nwhen the line was written (the article's purchase price at that\nmoment, or the `unit_cost` sent); converting the quote carries it\nto the worksheet's line. `null` when unknown.\n"
        },
        "total_before_tax": {
          "type": "number",
          "format": "double"
        },
        "total_tax": {
          "type": "number",
          "format": "double"
        },
        "total_after_tax": {
          "type": "number",
          "format": "double"
        },
        "position": {
          "type": "integer"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "WorkCategory": {
      "type": "object",
      "required": [
        "object",
        "id",
        "name"
      ],
      "properties": {
        "object": {
          "type": "string",
          "const": "work_category"
        },
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "name": {
          "type": "string"
        }
      }
    }
  }
}