{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://uklsp.org/schemas/v0.1/booking.schema.json",
  "title": "BookingRequest / BookingConfirmation",
  "description": "Request submitted by an agent and the server-authoritative confirmation returned.",
  "type": "object",
  "properties": {
    "booking_request": {
      "type": "object",
      "properties": {
        "request_id": {
          "type": "string",
          "pattern": "^req_[a-z0-9]{8,}$"
        },
        "provider_id": {
          "type": "string"
        },
        "service_code": {
          "type": "string"
        },
        "slot_id": {
          "type": "string"
        },
        "property": {
          "type": "object",
          "properties": {
            "postcode": {
              "type": "string",
              "pattern": "^[A-Z]{1,2}[0-9][A-Z0-9]? ?[0-9][A-Z]{2}$"
            },
            "address_line1": {
              "type": "string"
            },
            "access_notes": {
              "type": "string",
              "maxLength": 500
            }
          },
          "required": [
            "postcode",
            "address_line1"
          ],
          "additionalProperties": false
        },
        "customer": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
            "phone_e164": {
              "type": "string",
              "pattern": "^\\+44[0-9]{9,10}$"
            },
            "email": {
              "type": "string",
              "format": "email"
            },
            "role": {
              "type": "string",
              "enum": [
                "landlord",
                "agent_for_landlord",
                "homeowner",
                "tenant",
                "business"
              ]
            }
          },
          "required": [
            "name",
            "phone_e164"
          ],
          "additionalProperties": false
        },
        "agent": {
          "type": "object",
          "properties": {
            "agent_name": {
              "type": "string",
              "description": "e.g. 'Claude', 'ChatGPT', operator agent id."
            },
            "on_behalf_of_human": {
              "type": "boolean",
              "const": true,
              "description": "v0.1 requires a human principal for every booking."
            },
            "signature": {
              "type": "string",
              "description": "Optional HTTP message signature reference (Know-Your-Agent)."
            }
          },
          "required": [
            "agent_name",
            "on_behalf_of_human"
          ],
          "additionalProperties": false
        },
        "price_accepted": {
          "type": "object",
          "properties": {
            "amount": {
              "type": "number",
              "minimum": 0
            },
            "currency": {
              "type": "string",
              "const": "GBP"
            },
            "vat_treatment": {
              "type": "string",
              "enum": [
                "inc_vat",
                "ex_vat",
                "not_vat_registered"
              ]
            }
          },
          "required": [
            "amount",
            "currency",
            "vat_treatment"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "request_id",
        "provider_id",
        "service_code",
        "slot_id",
        "property",
        "customer",
        "agent"
      ],
      "additionalProperties": false
    },
    "booking_confirmation": {
      "type": "object",
      "properties": {
        "booking_id": {
          "type": "string",
          "pattern": "^bkg_[a-z0-9]{8,}$"
        },
        "request_id": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "confirmed",
            "held_pending_provider",
            "declined"
          ]
        },
        "confirmed_slot": {
          "$ref": "https://uklsp.org/schemas/v0.1/availability-slot.schema.json"
        },
        "price_confirmed": {
          "type": "object",
          "properties": {
            "amount": {
              "type": "number",
              "minimum": 0
            },
            "currency": {
              "type": "string",
              "const": "GBP"
            },
            "vat_treatment": {
              "type": "string",
              "enum": [
                "inc_vat",
                "ex_vat",
                "not_vat_registered"
              ]
            }
          },
          "required": [
            "amount",
            "currency",
            "vat_treatment"
          ],
          "additionalProperties": false
        },
        "cancellation_policy": {
          "type": "string",
          "maxLength": 500
        },
        "provider_reference": {
          "type": "string"
        },
        "deliverable": {
          "type": "string",
          "description": "What the customer receives, e.g. 'CP12 certificate PDF within 24h of visit'."
        }
      },
      "required": [
        "booking_id",
        "request_id",
        "status"
      ],
      "additionalProperties": false
    }
  },
  "required": [],
  "additionalProperties": false,
  "anyOf": [
    {
      "required": [
        "booking_request"
      ]
    },
    {
      "required": [
        "booking_confirmation"
      ]
    }
  ]
}
