{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://customshive/schemas/canonical/client.schema.json",
  "title": "CustomsHive Canonical Client Masterdata",
  "description": "JSON body for an ingestion-queue message carrying the application property MessageType = \"Client\". Sent by Business Central. Only the fields Business Central owns appear here — the customs fields (default procedure, C503, FR1, 4007, ET14000, CBAM, air transport rate and minimum) and the email address are owned by CustomsHive and are never overwritten by an import.",
  "type": "object",
  "required": ["clients"],
  "properties": {
    "clients": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/CanonicalClient" },
      "description": "The clients in this push. A batch rather than one message per client: masterdata arrives as a set."
    }
  },
  "$defs": {
    "CanonicalClient": {
      "type": "object",
      "required": ["code", "name"],
      "properties": {
        "code": {
          "type": "string",
          "minLength": 1,
          "maxLength": 20,
          "description": "The Business Central client code. The key the import upserts on."
        },
        "name": { "type": "string", "minLength": 1, "maxLength": 200 },
        "identification_number": {
          "type": ["string", "null"],
          "maxLength": 35,
          "description": "EORI. Lives in Business Central and follows it, unlike the email address."
        },
        "street_and_number": { "type": ["string", "null"], "maxLength": 70 },
        "postcode": { "type": ["string", "null"], "maxLength": 17 },
        "city": { "type": ["string", "null"], "maxLength": 35 },
        "country": {
          "type": ["string", "null"],
          "pattern": "^[A-Za-z]{2}$",
          "description": "ISO 3166-1 alpha-2."
        }
      }
    }
  }
}
