{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/officina-it/json-schema/officina-it-customer-schema.json",
  "title": "Customer",
  "description": "A workshop's client. Multi-tenant: belongs to one company.\nMost descriptive fields are optional (nullable) because\ncustomer records are commonly created from a phone call\nwith only a name and phone number.\n",
  "x-generated": "2026-11-19",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/officina-it-openapi.json#/components/schemas/Customer",
  "type": "object",
  "required": [
    "object",
    "id",
    "customer_type",
    "created_at",
    "updated_at"
  ],
  "properties": {
    "seq_number": {
      "type": [
        "integer",
        "null"
      ],
      "readOnly": true,
      "minimum": 1,
      "description": "Number within this company's creation year (the year of created_at). Null for unnumbered legacy records."
    },
    "version": {
      "type": "integer",
      "description": "Detail, create and PATCH responses only. Send it back as\n`If-Match` on PATCH: a save from an older copy is refused with 409.\n"
    },
    "price_list_discount_rate": {
      "type": "integer",
      "minimum": 1,
      "maximum": 99,
      "description": "Detail response only, absent when the customer's listino has no\nSconto generale. The discount every new line of this customer's\nworksheets and quotes starts from, typed lines included (the web\nand the app prefill it; line writes store the discount they send).\nShown to users who can read worksheets or quotes even without\n`customers.read`.\n"
    },
    "object": {
      "type": "string",
      "const": "customer"
    },
    "id": {
      "type": "string"
    },
    "customer_type": {
      "type": "string",
      "description": "Tax-status discriminator (e.g. \"private\", \"company\")."
    },
    "full_name": {
      "type": [
        "string",
        "null"
      ]
    },
    "email": {
      "type": [
        "string",
        "null"
      ],
      "format": "email"
    },
    "phone": {
      "type": [
        "string",
        "null"
      ],
      "description": "Stored E.164 value, e.g. \"+393331234567\"."
    },
    "phone_dial_code": {
      "type": [
        "string",
        "null"
      ],
      "description": "`phone` split server-side for the edit form's dial-code\nselector (e.g. \"+39\"). Null when `phone` is null.\n"
    },
    "phone_national": {
      "type": [
        "string",
        "null"
      ],
      "description": "`phone` minus the dial code, for the edit form's\nnational-number input. Null when `phone` is null.\n"
    },
    "address": {
      "type": [
        "string",
        "null"
      ]
    },
    "city": {
      "type": [
        "string",
        "null"
      ]
    },
    "zip_code": {
      "type": [
        "string",
        "null"
      ]
    },
    "province": {
      "type": [
        "string",
        "null"
      ]
    },
    "tax_id": {
      "type": [
        "string",
        "null"
      ],
      "description": "Partita IVA for an Italian customer; the VAT number without\ncountry prefix for a business elsewhere in the EU; free text\notherwise. See \"Partita IVA e numeri IVA UE\".\n"
    },
    "fiscal_code": {
      "type": [
        "string",
        "null"
      ],
      "description": "Italian fiscal code (codice fiscale) for individuals."
    },
    "pec": {
      "type": [
        "string",
        "null"
      ],
      "description": "Italian certified-email address for e-invoicing."
    },
    "destination_code": {
      "type": [
        "string",
        "null"
      ],
      "description": "Italian SDI destination code for e-invoicing."
    },
    "payment_method": {
      "type": [
        "string",
        "null"
      ]
    },
    "comments": {
      "type": [
        "string",
        "null"
      ]
    },
    "birthday": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "last_vehicle_name": {
      "type": [
        "string",
        "null"
      ],
      "description": "Display string of the customer's most recent vehicle\n(e.g. \"Fiat Panda\"). Pre-computed on the entity for\nlist-row rendering without a second request.\n"
    },
    "last_vehicle_license": {
      "type": [
        "string",
        "null"
      ]
    },
    "total_spent": {
      "type": "number",
      "format": "double",
      "description": "Lifetime spend (worksheet totals net of discounts), computed\nby the list query for row rendering. Money — render via the\nlocale formatter; avoid arithmetic.\n"
    },
    "documents": {
      "type": "array",
      "description": "Attachments (Documenti Allegati). Present on the detail\nresponse only; omitted on lists.\n",
      "items": {
        "$ref": "#/$defs/CustomerDocument"
      }
    },
    "custom_fields": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": true,
      "description": "Raw stored values keyed by custom field definition `id` (see\n`CustomerCustomFieldValues` for the stored shapes), on list rows\nand single-customer responses (GET, POST, PATCH). Includes hidden\nfields. Omitted when the customer has no values. On lists since\nrevision 2026-11-02 (served to every revision).\n"
    },
    "custom_field_values": {
      "type": "array",
      "description": "`GET /v1/customers/{id}` only. The company's visible custom\nfield definitions (settings → Campi cliente) resolved against\nthis customer: configured order, display-ready names, \"\"\nwhen the customer has no value.\n",
      "items": {
        "type": "object",
        "required": [
          "id",
          "name",
          "type",
          "value"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "string",
              "integer",
              "datetime",
              "list"
            ]
          },
          "options": {
            "type": "array",
            "x-since": "2026-10-23",
            "items": {
              "type": "string"
            },
            "description": "`list` fields only (omitted on the other types): the\ndropdown choices in order, so the picker renders\nwithout a settings lookup. `value` is one of them, or\n\"\" when unset.\n"
          },
          "value": {
            "type": "string"
          }
        }
      }
    },
    "field_visibility": {
      "type": "object",
      "description": "`GET /v1/customers/{id}` only. The company's optional-field\ntoggles (settings → Campi cliente): the edit form hides — and\nomits from its PATCH — exactly what the web form hides. All\ntrue when never configured.\n",
      "properties": {
        "birthday": {
          "type": "boolean"
        },
        "comments": {
          "type": "boolean"
        }
      }
    },
    "next_appointment": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    },
    "deleted_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "Soft-deletion timestamp. Populated on the response from\nDELETE /v1/customers/{id}. Customers with a non-null\ndeleted_at are not returned by list/detail endpoints —\nthis field appears for the delete response only.\n"
    }
  },
  "$defs": {
    "CustomerDocument": {
      "type": "object",
      "required": [
        "object",
        "id",
        "name",
        "content_type",
        "url",
        "file_size_bytes",
        "created_at"
      ],
      "description": "One customer attachment. `url` is the document's authenticated\ndownload route\n(`/v1/customers/{id}/documents/{documentID}/download`) — fetch it\nwith the bearer to stream the bytes.\n",
      "properties": {
        "object": {
          "type": "string",
          "const": "customer_document"
        },
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "content_type": {
          "type": "string"
        },
        "description": {
          "type": [
            "string",
            "null"
          ]
        },
        "url": {
          "type": "string"
        },
        "file_size_bytes": {
          "type": "integer"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    }
  }
}