{
  "openapi": "3.1.0",
  "info": {
    "title": "DriveStable Vehicle Passport Connect API",
    "version": "0.1.0",
    "description": "Controlled garage pilot. Interactive OAuth authorisation; no unattended service-account writes. The configured API base URL is supplied at onboarding."
  },
  "tags": [
    {
      "name": "Garage Passport",
      "description": "Holder-authorised garage contributions to the canonical Passport."
    }
  ],
  "paths": {
    "/v1/garage-gateway": {
      "get": {
        "tags": ["Garage Passport"],
        "summary": "List authorised service cases",
        "operationId": "listGarageServiceCases",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-drivestable-status": "implemented",
        "description": "Controlled activation requires GARAGE_GATEWAY_ENABLED=true, migrated schema and dedicated evidence bucket. OAuth audience and approved client are required; the vehicle holder and garage permissions are checked separately.",
        "parameters": [
          {
            "in": "query",
            "name": "organisationId",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Approved garage workspace selector. Omit for the holder. Never proof of authority."
          },
          {
            "in": "query",
            "name": "after",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque continuation value from nextCursor."
          }
        ],
        "responses": {
          "200": {
            "description": "Completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GaragePage"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Authority is not active"
          },
          "404": {
            "description": "Authorised record not found"
          },
          "409": {
            "description": "Immutable decision or replay conflict"
          },
          "413": {
            "description": "Request exceeds allowance"
          },
          "415": {
            "description": "Unsupported document type"
          },
          "429": {
            "description": "Rate allowance reached"
          },
          "503": {
            "description": "Gateway or required provider unavailable"
          }
        }
      }
    },
    "/v1/garage-gateway/cases": {
      "post": {
        "tags": ["Garage Passport"],
        "summary": "Holder authorises a service case",
        "operationId": "openGarageServiceCase",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-drivestable-status": "implemented",
        "description": "Controlled activation requires GARAGE_GATEWAY_ENABLED=true, migrated schema and dedicated evidence bucket. OAuth audience and approved client are required; the vehicle holder and garage permissions are checked separately.",
        "parameters": [],
        "responses": {
          "201": {
            "description": "Completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Authority is not active"
          },
          "404": {
            "description": "Authorised record not found"
          },
          "409": {
            "description": "Immutable decision or replay conflict"
          },
          "413": {
            "description": "Request exceeds allowance"
          },
          "415": {
            "description": "Unsupported document type"
          },
          "429": {
            "description": "Rate allowance reached"
          },
          "503": {
            "description": "Gateway or required provider unavailable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GarageOpenCase"
              }
            }
          }
        }
      }
    },
    "/v1/garage-gateway/cases/{caseId}": {
      "get": {
        "tags": ["Garage Passport"],
        "summary": "Review a service case and its original evidence",
        "operationId": "readGarageServiceCase",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-drivestable-status": "implemented",
        "description": "Controlled activation requires GARAGE_GATEWAY_ENABLED=true, migrated schema and dedicated evidence bucket. OAuth audience and approved client are required; the vehicle holder and garage permissions are checked separately.",
        "parameters": [
          {
            "in": "path",
            "name": "caseId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "organisationId",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Approved garage workspace selector. Omit for the holder. Never proof of authority."
          }
        ],
        "responses": {
          "200": {
            "description": "Completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GarageCaseDetail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Authority is not active"
          },
          "404": {
            "description": "Authorised record not found"
          },
          "409": {
            "description": "Immutable decision or replay conflict"
          },
          "413": {
            "description": "Request exceeds allowance"
          },
          "415": {
            "description": "Unsupported document type"
          },
          "429": {
            "description": "Rate allowance reached"
          },
          "503": {
            "description": "Gateway or required provider unavailable"
          }
        }
      }
    },
    "/v1/garage-gateway/cases/{caseId}/commands": {
      "post": {
        "tags": ["Garage Passport"],
        "summary": "Issue quote, decide, book, complete or consent to publication",
        "operationId": "commandGarageServiceCase",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-drivestable-status": "implemented",
        "description": "Controlled activation requires GARAGE_GATEWAY_ENABLED=true, migrated schema and dedicated evidence bucket. OAuth audience and approved client are required; the vehicle holder and garage permissions are checked separately.",
        "parameters": [
          {
            "in": "path",
            "name": "caseId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "organisationId",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Approved garage workspace selector. Omit for the holder. Never proof of authority."
          }
        ],
        "responses": {
          "200": {
            "description": "Completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Authority is not active"
          },
          "404": {
            "description": "Authorised record not found"
          },
          "409": {
            "description": "Immutable decision or replay conflict"
          },
          "413": {
            "description": "Request exceeds allowance"
          },
          "415": {
            "description": "Unsupported document type"
          },
          "429": {
            "description": "Rate allowance reached"
          },
          "503": {
            "description": "Gateway or required provider unavailable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GarageCommand"
              }
            }
          }
        }
      }
    },
    "/v1/garage-gateway/cases/{caseId}/documents": {
      "post": {
        "tags": ["Garage Passport"],
        "summary": "Upload a private invoice or service record",
        "operationId": "uploadGarageServiceDocument",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-drivestable-status": "implemented",
        "description": "Controlled activation requires GARAGE_GATEWAY_ENABLED=true, migrated schema and dedicated evidence bucket. OAuth audience and approved client are required; the vehicle holder and garage permissions are checked separately. Holders omit organisationId and may upload only owner_document in their own authorised case. Other document kinds require an approved garage workspace. Owner documents are shared with that case garage and are not automatically published.",
        "parameters": [
          {
            "in": "path",
            "name": "caseId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "organisationId",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Approved garage workspace selector. Omit for the holder. Never proof of authority."
          },
          {
            "in": "query",
            "name": "kind",
            "required": true,
            "schema": {
              "enum": ["invoice", "service_record", "owner_document"]
            }
          },
          {
            "name": "uploadId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Stable document identifier for an identical retry; conflicting bytes or case are rejected."
          }
        ],
        "responses": {
          "201": {
            "description": "Completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Authority is not active"
          },
          "404": {
            "description": "Authorised record not found"
          },
          "409": {
            "description": "Immutable decision or replay conflict"
          },
          "413": {
            "description": "Request exceeds allowance"
          },
          "415": {
            "description": "Unsupported document type"
          },
          "429": {
            "description": "Rate allowance reached"
          },
          "503": {
            "description": "Gateway or required provider unavailable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/pdf": {
              "schema": {
                "type": "string",
                "format": "binary",
                "maxLength": 5000000
              }
            },
            "image/jpeg": {
              "schema": {
                "type": "string",
                "format": "binary",
                "maxLength": 5000000
              }
            },
            "image/png": {
              "schema": {
                "type": "string",
                "format": "binary",
                "maxLength": 5000000
              }
            }
          }
        }
      }
    },
    "/v1/garage-gateway/cases/{caseId}/documents/{objectId}": {
      "get": {
        "tags": ["Garage Passport"],
        "summary": "Download an authorised original with digest verification",
        "operationId": "downloadGarageServiceDocument",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-drivestable-status": "implemented",
        "description": "Controlled activation requires GARAGE_GATEWAY_ENABLED=true, migrated schema and dedicated evidence bucket. OAuth audience and approved client are required; the vehicle holder and garage permissions are checked separately.",
        "parameters": [
          {
            "in": "path",
            "name": "caseId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "objectId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "organisationId",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Approved garage workspace selector. Omit for the holder. Never proof of authority."
          }
        ],
        "responses": {
          "200": {
            "description": "Completed successfully",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Authority is not active"
          },
          "404": {
            "description": "Authorised record not found"
          },
          "409": {
            "description": "Immutable decision or replay conflict"
          },
          "413": {
            "description": "Request exceeds allowance"
          },
          "415": {
            "description": "Unsupported document type"
          },
          "429": {
            "description": "Rate allowance reached"
          },
          "503": {
            "description": "Gateway or required provider unavailable"
          }
        }
      }
    },
    "/v1/garage-gateway/passports/{vehicleId}/events": {
      "get": {
        "tags": ["Garage Passport"],
        "summary": "Read holder-authorised shared Passport events",
        "operationId": "readSharedPassportEvents",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-drivestable-status": "implemented",
        "description": "Controlled activation requires GARAGE_GATEWAY_ENABLED=true, migrated schema and dedicated evidence bucket. OAuth audience and approved client are required; the vehicle holder and garage permissions are checked separately.",
        "parameters": [
          {
            "in": "path",
            "name": "vehicleId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "after",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque continuation value from nextCursor."
          }
        ],
        "responses": {
          "200": {
            "description": "Completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GarageHistory"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Authority is not active"
          },
          "404": {
            "description": "Authorised record not found"
          },
          "409": {
            "description": "Immutable decision or replay conflict"
          },
          "413": {
            "description": "Request exceeds allowance"
          },
          "415": {
            "description": "Unsupported document type"
          },
          "429": {
            "description": "Rate allowance reached"
          },
          "503": {
            "description": "Gateway or required provider unavailable"
          }
        }
      }
    },
    "/v1/garage-gateway/access-requests": {
      "post": {
        "tags": ["Garage Passport"],
        "summary": "Request approval for a garage workspace",
        "operationId": "requestGarageGatewayAccess",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-drivestable-status": "implemented",
        "description": "Controlled activation requires GARAGE_GATEWAY_ENABLED=true, migrated schema and dedicated evidence bucket. OAuth audience and approved client are required; the vehicle holder and garage permissions are checked separately.",
        "parameters": [],
        "responses": {
          "201": {
            "description": "Completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Authority is not active"
          },
          "404": {
            "description": "Authorised record not found"
          },
          "409": {
            "description": "Immutable decision or replay conflict"
          },
          "413": {
            "description": "Request exceeds allowance"
          },
          "415": {
            "description": "Unsupported document type"
          },
          "429": {
            "description": "Rate allowance reached"
          },
          "503": {
            "description": "Gateway or required provider unavailable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GarageAccessRequest"
              }
            }
          }
        }
      }
    },
    "/v1/garage-gateway/passports/{vehicleId}/records": {
      "post": {
        "tags": ["Garage Passport"],
        "summary": "Save a private, owner-supplied record to the canonical Passport",
        "operationId": "addHolderPassportRecord",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-drivestable-status": "implemented",
        "description": "Controlled activation requires GARAGE_GATEWAY_ENABLED=true, migrated schema and dedicated evidence bucket. OAuth audience and approved client are required; the vehicle holder and garage permissions are checked separately.",
        "parameters": [
          {
            "name": "vehicleId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Authority is not active"
          },
          "404": {
            "description": "Authorised record not found"
          },
          "409": {
            "description": "Immutable decision or replay conflict"
          },
          "413": {
            "description": "Request exceeds allowance"
          },
          "415": {
            "description": "Unsupported document type"
          },
          "429": {
            "description": "Rate allowance reached"
          },
          "503": {
            "description": "Gateway or required provider unavailable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HolderPassportRecord"
              }
            }
          }
        }
      }
    },
    "/v1/garage-gateway/cases/{caseId}/invoices/{invoiceId}": {
      "get": {
        "tags": ["Garage Passport"],
        "summary": "Download an immutable, numbered invoice from the approved quote",
        "operationId": "downloadGarageInvoice",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-drivestable-status": "implemented",
        "description": "Controlled activation requires GARAGE_GATEWAY_ENABLED=true, migrated schema and dedicated evidence bucket. OAuth audience and approved client are required; the vehicle holder and garage permissions are checked separately.",
        "parameters": [
          {
            "in": "path",
            "name": "caseId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "invoiceId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "organisationId",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Approved garage workspace selector. Omit for the holder. Never proof of authority."
          }
        ],
        "responses": {
          "200": {
            "description": "Completed successfully",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Authority is not active"
          },
          "404": {
            "description": "Authorised record not found"
          },
          "409": {
            "description": "Immutable decision or replay conflict"
          },
          "413": {
            "description": "Request exceeds allowance"
          },
          "415": {
            "description": "Unsupported document type"
          },
          "429": {
            "description": "Rate allowance reached"
          },
          "503": {
            "description": "Gateway or required provider unavailable"
          }
        }
      }
    },
    "/v1/garage-gateway/passports/{vehicleId}/export": {
      "get": {
        "tags": ["Garage Passport"],
        "summary": "Download one page of shared Passport records, excluding private notes and billing documents",
        "operationId": "exportSharedPassportRecordPage",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-drivestable-status": "implemented",
        "description": "Controlled activation requires GARAGE_GATEWAY_ENABLED=true, migrated schema and dedicated evidence bucket. OAuth audience and approved client are required; the vehicle holder and garage permissions are checked separately.",
        "parameters": [
          {
            "in": "path",
            "name": "vehicleId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "after",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque continuation value from nextCursor."
          }
        ],
        "responses": {
          "200": {
            "description": "Completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "vehicleId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "scope": {
                      "const": "shared_passport_page"
                    },
                    "explanation": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 500
                    },
                    "records": {
                      "type": "array",
                      "maxItems": 50,
                      "items": {
                        "type": "object"
                      }
                    },
                    "nextCursor": {
                      "type": ["string", "null"],
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "vehicleId",
                    "scope",
                    "explanation",
                    "records",
                    "nextCursor"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Authority is not active"
          },
          "404": {
            "description": "Authorised record not found"
          },
          "409": {
            "description": "Immutable decision or replay conflict"
          },
          "413": {
            "description": "Request exceeds allowance"
          },
          "415": {
            "description": "Unsupported document type"
          },
          "429": {
            "description": "Rate allowance reached"
          },
          "503": {
            "description": "Gateway or required provider unavailable"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {
      "GarageOpenCase": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "garageOrganisationId": {
            "type": "string",
            "format": "uuid"
          },
          "vehicleId": {
            "type": "string",
            "format": "uuid"
          },
          "summary": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": ["id", "garageOrganisationId", "vehicleId", "summary"]
      },
      "GarageCommand": {
        "oneOf": [
          {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "action": {
                "const": "quote"
              },
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "seriesId": {
                "type": "string",
                "format": "uuid"
              },
              "version": {
                "type": "integer",
                "minimum": 1
              },
              "supersedesQuoteId": {
                "type": "string",
                "format": "uuid"
              },
              "validDays": {
                "type": "integer",
                "minimum": 1,
                "maximum": 31
              },
              "warrantySummary": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500
              },
              "lines": {
                "type": "array",
                "minItems": 1,
                "maxItems": 100,
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "kind": {
                      "enum": ["part", "labour", "other"]
                    },
                    "description": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 240
                    },
                    "quantity": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 10000
                    },
                    "unitNetPence": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 1000000000
                    },
                    "vatRateBasisPoints": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 10000
                    }
                  },
                  "required": [
                    "kind",
                    "description",
                    "quantity",
                    "unitNetPence",
                    "vatRateBasisPoints"
                  ]
                }
              }
            },
            "required": [
              "action",
              "id",
              "seriesId",
              "version",
              "validDays",
              "warrantySummary",
              "lines"
            ]
          },
          {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "action": {
                "const": "decide"
              },
              "quoteId": {
                "type": "string",
                "format": "uuid"
              },
              "decision": {
                "enum": ["reviewed", "approved", "declined", "change_requested"]
              },
              "reason": {
                "type": "string",
                "minLength": 1,
                "maxLength": 1000
              }
            },
            "required": ["action", "quoteId", "decision"]
          },
          {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "action": {
                "const": "book"
              },
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "quoteId": {
                "type": "string",
                "format": "uuid"
              }
            },
            "required": ["action", "id", "quoteId"]
          },
          {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "action": {
                "const": "complete"
              },
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "bookingId": {
                "type": "string",
                "format": "uuid"
              },
              "invoiceEvidenceId": {
                "type": "string",
                "format": "uuid"
              },
              "serviceEvidenceId": {
                "type": "string",
                "format": "uuid"
              },
              "attested": {
                "const": true
              }
            },
            "required": [
              "action",
              "id",
              "bookingId",
              "invoiceEvidenceId",
              "serviceEvidenceId",
              "attested"
            ]
          },
          {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "action": {
                "const": "publish"
              },
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "eventId": {
                "type": "string",
                "format": "uuid"
              },
              "consentId": {
                "type": "string",
                "format": "uuid"
              },
              "consentedAt": {
                "type": "string",
                "format": "date-time"
              },
              "consented": {
                "const": true
              }
            },
            "required": [
              "action",
              "id",
              "eventId",
              "consentId",
              "consentedAt",
              "consented"
            ]
          },
          {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "const": "invoice"
              },
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "bookingId": {
                "type": "string",
                "format": "uuid"
              },
              "attested": {
                "type": "boolean",
                "const": true
              },
              "supplierName": {
                "type": "string",
                "minLength": 1,
                "maxLength": 160
              },
              "supplierAddress": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500
              },
              "contactEmail": {
                "type": "string",
                "format": "email",
                "maxLength": 254
              },
              "customerName": {
                "type": "string",
                "minLength": 1,
                "maxLength": 160
              },
              "customerAddress": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500
              },
              "vatNumber": {
                "type": ["string", "null"],
                "maxLength": 14
              },
              "supplyDate": {
                "type": "string",
                "format": "date"
              },
              "dueDate": {
                "type": "string",
                "format": "date"
              },
              "paymentTerms": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500
              }
            },
            "required": [
              "action",
              "id",
              "bookingId",
              "attested",
              "supplierName",
              "supplierAddress",
              "contactEmail",
              "customerName",
              "customerAddress",
              "vatNumber",
              "supplyDate",
              "dueDate",
              "paymentTerms"
            ]
          }
        ]
      },
      "GarageCase": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "garage_organisation_id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_user_id": {
            "type": "string",
            "format": "uuid"
          },
          "vehicle_id": {
            "type": "string",
            "format": "uuid"
          },
          "owner_summary": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "id",
          "garage_organisation_id",
          "customer_user_id",
          "vehicle_id",
          "owner_summary"
        ]
      },
      "GaragePage": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "garages": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "name": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 160
                }
              },
              "required": ["id", "name"]
            }
          },
          "cases": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "$ref": "#/components/schemas/GarageCase"
            }
          },
          "nextCursor": {
            "type": ["string", "null"],
            "format": "uuid"
          },
          "workspaces": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "name": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 160
                }
              },
              "required": ["id", "name"]
            }
          },
          "accessRequest": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "business_name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 160
                  },
                  "postcode": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 10
                  },
                  "contact_email": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 254
                  },
                  "state": {
                    "type": "string",
                    "enum": ["pending", "approved", "declined"]
                  }
                },
                "required": [
                  "id",
                  "business_name",
                  "postcode",
                  "contact_email",
                  "state"
                ]
              }
            ]
          }
        },
        "required": [
          "garages",
          "cases",
          "nextCursor",
          "workspaces",
          "accessRequest"
        ]
      },
      "GarageCaseDetail": {
        "type": "object",
        "required": [
          "serviceCase",
          "quotes",
          "lines",
          "evidence",
          "bookings",
          "completions",
          "publications",
          "invoices"
        ],
        "properties": {
          "serviceCase": {
            "$ref": "#/components/schemas/GarageCase"
          },
          "quotes": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "lines": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "evidence": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "bookings": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "completions": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "publications": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "invoices": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "invoice_number": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 40
                },
                "booking_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "issued_on": {
                  "type": "string",
                  "format": "date"
                }
              },
              "required": ["id", "invoice_number", "booking_id", "issued_on"]
            }
          }
        }
      },
      "GarageHistory": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "vehicleId": {
            "type": "string",
            "format": "uuid"
          },
          "events": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "event_type": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 120
                },
                "occurred_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "issuer_name": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 240
                },
                "verification_level": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 40
                },
                "title": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 120
                },
                "issuer_type": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 32
                },
                "visibility_scope": {
                  "type": "string",
                  "enum": ["shared_passport", "passport_holder"]
                },
                "metadata": {
                  "type": "object",
                  "additionalProperties": true
                }
              },
              "required": [
                "id",
                "event_type",
                "occurred_at",
                "issuer_name",
                "verification_level",
                "title",
                "issuer_type",
                "visibility_scope",
                "metadata"
              ]
            }
          },
          "nextCursor": {
            "type": ["string", "null"],
            "format": "uuid"
          }
        },
        "required": ["vehicleId", "events", "nextCursor"]
      },
      "GarageAccessRequest": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "businessName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 160
          },
          "postcode": {
            "type": "string",
            "minLength": 1,
            "maxLength": 10
          },
          "contactEmail": {
            "type": "string",
            "format": "email",
            "maxLength": 254
          }
        },
        "required": ["id", "businessName", "postcode", "contactEmail"]
      },
      "HolderPassportRecord": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "category": {
            "type": "string",
            "enum": [
              "service",
              "repair",
              "tyres",
              "modification",
              "warranty",
              "running_cost",
              "manufacturer_document"
            ]
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time"
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "supplier": {
            "type": ["string", "null"],
            "maxLength": 160
          },
          "mileage": {
            "type": ["integer", "null"],
            "minimum": 0,
            "maximum": 10000000
          },
          "costPence": {
            "type": ["integer", "null"],
            "minimum": 0,
            "maximum": 1000000000
          }
        },
        "required": [
          "id",
          "category",
          "occurredAt",
          "title",
          "description",
          "supplier",
          "mileage",
          "costPence"
        ]
      }
    }
  }
}
