{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/officina-it/json-schema/officina-it-vehicle-schema.json",
  "title": "Vehicle",
  "description": "A vehicle owned (or managed) by a workshop client.\nMulti-tenant: belongs to one company. `manufacturer_name`\nand `customer_name` are joined-in convenience fields\npopulated by the repository so list rows can render\n`Fiat Panda — Mario Rossi` without a follow-up request.\n\nRental fields are read-only on this resource. Mutate them\nvia the dedicated rental setup flow.\n",
  "x-generated": "2026-11-19",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/officina-it-openapi.json#/components/schemas/Vehicle",
  "type": "object",
  "required": [
    "object",
    "id",
    "manufacturer_id",
    "manufacturer_name",
    "model",
    "is_rental",
    "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"
    },
    "object": {
      "type": "string",
      "const": "vehicle"
    },
    "id": {
      "type": "string"
    },
    "license": {
      "type": [
        "string",
        "null"
      ],
      "description": "License plate (regional format, free-form string)."
    },
    "manufacturer_id": {
      "type": "string"
    },
    "manufacturer_name": {
      "type": "string",
      "description": "Joined from the manufacturers table for display.\nRead-only; mutate via `manufacturer_id`.\n"
    },
    "model": {
      "type": "string"
    },
    "variant": {
      "type": [
        "string",
        "null"
      ]
    },
    "vin": {
      "type": [
        "string",
        "null"
      ],
      "description": "Vehicle Identification Number."
    },
    "transmission": {
      "type": [
        "string",
        "null"
      ]
    },
    "engine_power_kw": {
      "type": [
        "number",
        "null"
      ],
      "minimum": 0.01,
      "maximum": 2000,
      "description": "Potenza motore in kW, up to two decimals (110.5). On writes, greater than 0 and at most 2000 on every revision (`422` on `/engine_power_kw` otherwise; more decimals are rounded to two; a 0 from a client declaring a revision before 2026-11-09 is stored as empty). Clients declaring a revision before 2026-11-09 read it rounded half away from zero to an integer, and a `PATCH` sending that rounded value back keeps the stored one."
    },
    "engine_displacement_ccm": {
      "type": [
        "integer",
        "null"
      ]
    },
    "engine_code": {
      "type": [
        "string",
        "null"
      ],
      "x-since": "2026-10-05",
      "description": "Codice motore. Stored trimmed and upper case (max 64 characters); an empty string or `null` clears it. When empty, officina.it may fill it from the vehicle's registration data. Shown in the app when `field_visibility.engine_code` is on."
    },
    "vehicle_weight_kg": {
      "type": [
        "integer",
        "null"
      ]
    },
    "engine_category": {
      "type": [
        "string",
        "null"
      ]
    },
    "registered_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "comments": {
      "type": [
        "string",
        "null"
      ]
    },
    "customer_id": {
      "type": [
        "string",
        "null"
      ]
    },
    "customer_name": {
      "type": [
        "string",
        "null"
      ],
      "description": "Joined from the owning customer's `full_name` for\ndisplay. Read-only; mutate via `customer_id`.\n"
    },
    "km": {
      "type": [
        "number",
        "null"
      ],
      "description": "Most recently recorded odometer reading."
    },
    "km_registered_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "last_inspection_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "next_inspection_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "next_appointment": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "Earliest upcoming calendar appointment for this vehicle,\ncomputed at read time.\n"
    },
    "custom_fields": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": true,
      "description": "Raw stored values keyed by custom field definition `id`\n(see `VehicleCustomFieldValues` for the stored shapes), on\nlist rows and detail responses; `null` when the vehicle has\nnone. Includes hidden fields, and on older records keys of\ndeleted definitions (dropped on the next PATCH that sends\n`custom_fields`). Filled on list rows since revision 2026-11-02\n(served to every revision).\n"
    },
    "custom_field_values": {
      "type": "array",
      "description": "Detail responses only. The company's visible custom field\ndefinitions (settings → Campi veicolo) resolved against\nthis vehicle: configured order, display-ready names, \"\"\nwhen the vehicle has no value. Clients render these\ndirectly — no definition lookup needed.\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"
          }
        }
      }
    },
    "documents": {
      "type": "array",
      "description": "Detail responses only — the vehicle's Documenti Allegati.\n`url` is the authenticated download route\n(`/v1/vehicles/{id}/documents/{documentID}/download`).\n",
      "items": {
        "$ref": "#/$defs/VehicleDocument"
      }
    },
    "field_visibility": {
      "type": "object",
      "description": "Detail responses only. The company's optional-field\ntoggles (settings → Campi veicolo): the edit form hides —\nand omits from its PATCH — exactly what the web form\nhides. All true when never configured.\n",
      "properties": {
        "km": {
          "type": "boolean"
        },
        "numero_telaio": {
          "type": "boolean"
        },
        "transmission": {
          "type": "boolean"
        },
        "engine_category": {
          "type": "boolean"
        },
        "engine_power_kw": {
          "type": "boolean"
        },
        "engine_displacement_ccm": {
          "type": "boolean"
        },
        "engine_code": {
          "type": "boolean",
          "x-since": "2026-10-05"
        },
        "vehicle_weight_kg": {
          "type": "boolean"
        },
        "registration_date": {
          "type": "boolean"
        },
        "last_inspection_date": {
          "type": "boolean"
        },
        "next_inspection_date": {
          "type": "boolean"
        }
      }
    },
    "is_rental": {
      "type": "boolean",
      "description": "Whether this vehicle is part of the workshop's rental\nfleet. Read-only here — managed by the rental setup flow.\n"
    },
    "rental_daily_price_before_tax": {
      "type": [
        "number",
        "null"
      ]
    },
    "rental_daily_price_tax": {
      "type": [
        "number",
        "null"
      ]
    },
    "rental_daily_price_after_tax": {
      "type": [
        "number",
        "null"
      ]
    },
    "rental_vat_code": {
      "type": [
        "string",
        "null"
      ]
    },
    "rental_daily_discount_rate": {
      "type": [
        "number",
        "null"
      ]
    },
    "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/vehicles/{id}. Vehicles with a non-null\ndeleted_at are not returned by list/detail endpoints —\nthis field appears for the delete response only.\n"
    }
  },
  "$defs": {
    "VehicleDocument": {
      "type": "object",
      "required": [
        "object",
        "id",
        "name",
        "content_type",
        "description",
        "url",
        "file_size_bytes",
        "created_at"
      ],
      "description": "One attachment on a vehicle (Documenti Allegati). `url` is the\nauthenticated download route — fetch it with the bearer and\nhand the bytes to the OS viewer/share sheet.\n",
      "properties": {
        "object": {
          "type": "string",
          "const": "vehicle_document"
        },
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string",
          "description": "Original file name."
        },
        "content_type": {
          "type": "string"
        },
        "description": {
          "type": [
            "string",
            "null"
          ]
        },
        "url": {
          "type": "string"
        },
        "file_size_bytes": {
          "type": "integer"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    }
  }
}