{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "$id": "https://brainclub.com/schemas/delivery-quote.json",
 "title": "A delivery quote: the ways to send a parcel from one place to another, cheapest first",
 "x-version": 1,
 "oneOf": [
  {
   "type": "object",
   "properties": {
    "ok": {
     "const": true
    },
    "version": {
     "type": "integer",
     "minimum": 1
    },
    "region": {
     "type": "string"
    },
    "lang": {
     "type": "string"
    },
    "checked": {
     "type": [
      "string",
      "null"
     ],
     "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
     "description": "YYYY-MM-DD"
    },
    "stale": {
     "type": "boolean"
    },
    "from": {
     "type": "object",
     "properties": {
      "country": {
       "type": "string",
       "pattern": "^[A-Z]{2}$",
       "description": "ISO 3166-1 alpha-2"
      },
      "town": {
       "type": [
        "string",
        "null"
       ]
      },
      "postcode": {
       "type": [
        "string",
        "null"
       ]
      }
     },
     "required": [
      "country",
      "town",
      "postcode"
     ],
     "additionalProperties": false
    },
    "to": {
     "type": "object",
     "properties": {
      "country": {
       "type": "string",
       "pattern": "^[A-Z]{2}$",
       "description": "ISO 3166-1 alpha-2"
      },
      "town": {
       "type": [
        "string",
        "null"
       ]
      },
      "postcode": {
       "type": [
        "string",
        "null"
       ]
      }
     },
     "required": [
      "country",
      "town",
      "postcode"
     ],
     "additionalProperties": false
    },
    "parcel": {
     "type": "object",
     "properties": {
      "l": {
       "type": "number",
       "minimum": 0
      },
      "w": {
       "type": "number",
       "minimum": 0
      },
      "h": {
       "type": "number",
       "minimum": 0
      },
      "kg": {
       "type": "number",
       "minimum": 0
      },
      "preset": {
       "type": [
        "string",
        "null"
       ],
       "enum": [
        "S",
        "M",
        "L",
        "XL",
        null
       ]
      }
     },
     "required": [
      "l",
      "w",
      "h",
      "kg",
      "preset"
     ],
     "additionalProperties": false
    },
    "verdict": {
     "type": "string",
     "enum": [
      "ok",
      "no_locker",
      "nothing_fits"
     ]
    },
    "options": {
     "type": "array",
     "items": {
      "type": "object",
      "properties": {
       "carrier": {
        "type": "string"
       },
       "carrier_id": {
        "type": "string",
        "pattern": "^[a-z0-9-]+$"
       },
       "country": {
        "type": "string",
        "pattern": "^[A-Z]{2}$",
        "description": "ISO 3166-1 alpha-2"
       },
       "way": {
        "type": "string",
        "enum": [
         "locker",
         "courier",
         "post"
        ]
       },
       "drop": {
        "type": "string",
        "enum": [
         "locker",
         "point",
         "post",
         "door"
        ]
       },
       "size": {
        "type": "string",
        "pattern": "^(?:XXS|XS|S|M|L|XL|XXL|QS|QM|\\d+(?:\\.\\d+)?(?:-\\d+(?:\\.\\d+)?)? (?:g|kg))$"
       },
       "kind": {
        "type": [
         "string",
         "null"
        ],
        "enum": [
         "small_plain",
         "small_tracked",
         "small_registered",
         "parcel_registered",
         null
        ]
       },
       "fits": {
        "type": "boolean"
       },
       "why": {
        "type": [
         "string",
         "null"
        ],
        "enum": [
         "too_heavy",
         "too_big",
         "too_light",
         null
        ]
       },
       "price_eur": {
        "type": [
         "number",
         "null"
        ],
        "minimum": 0
       },
       "vat": {
        "type": "string",
        "enum": [
         "included",
         "excluded",
         "unknown"
        ]
       },
       "days": {
        "type": [
         "array",
         "null"
        ],
        "items": {
         "type": "integer",
         "minimum": 0,
         "maximum": 60
        },
        "minItems": 2,
        "maxItems": 2,
        "description": "[min, max] WORKING days as the carrier publishes them; null when it publishes none"
       },
       "limits": {
        "type": "object",
        "properties": {
         "l": {
          "type": "number",
          "minimum": 0
         },
         "w": {
          "type": "number",
          "minimum": 0
         },
         "h": {
          "type": "number",
          "minimum": 0
         },
         "kg": {
          "type": "number",
          "minimum": 0
         },
         "sum": {
          "type": "number",
          "minimum": 0
         },
         "girth": {
          "type": "number",
          "minimum": 0
         },
         "longest": {
          "type": "number",
          "minimum": 0
         },
         "kg_min": {
          "type": "number",
          "minimum": 0
         },
         "vol_div": {
          "type": "number",
          "minimum": 1
         }
        },
        "required": [
         "kg"
        ],
        "additionalProperties": false,
        "description": "centimetres and kilograms; l/w/h a box the parcel must fit in any orientation; sum = l+w+h; girth = longest + 2 × (the other two); kg_min the least a service takes; vol_div: the kg limit applies to the greater of the real weight and l×w×h ÷ vol_div (volumetric weight)"
       },
       "how": {
        "type": "object",
        "properties": {
         "url": {
          "type": "string",
          "pattern": "^https://",
          "description": "a public https page"
         },
         "steps": {
          "type": "array",
          "items": {
           "type": "string"
          }
         }
        },
        "required": [
         "url",
         "steps"
        ],
        "additionalProperties": false
       },
       "source": {
        "type": "string",
        "pattern": "^https://",
        "description": "a public https page"
       },
       "checked": {
        "type": "string",
        "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
        "description": "YYYY-MM-DD"
       },
       "stale": {
        "type": "boolean"
       },
       "note": {
        "type": "string"
       }
      },
      "required": [
       "carrier",
       "carrier_id",
       "country",
       "way",
       "drop",
       "size",
       "kind",
       "fits",
       "why",
       "price_eur",
       "vat",
       "days",
       "limits",
       "how",
       "source",
       "checked",
       "stale",
       "note"
      ],
      "additionalProperties": false
     }
    },
    "cheapest": {
     "type": [
      "integer",
      "null"
     ],
     "minimum": 0
    },
    "fastest": {
     "type": [
      "integer",
      "null"
     ],
     "minimum": 0
    },
    "in_app": {
     "type": "array",
     "items": {
      "type": "object",
      "properties": {
       "carrier": {
        "type": "string"
       },
       "carrier_id": {
        "type": "string",
        "pattern": "^[a-z0-9-]+$"
       },
       "country": {
        "type": "string",
        "pattern": "^[A-Z]{2}$",
        "description": "ISO 3166-1 alpha-2"
       },
       "town": {
        "type": "string"
       },
       "price": {
        "const": "in_app",
        "description": "the carrier shows the price only in its app, before ordering"
       },
       "fits": {
        "type": "boolean"
       },
       "why": {
        "type": [
         "string",
         "null"
        ],
        "enum": [
         "too_heavy",
         "too_big",
         "too_light",
         null
        ]
       },
       "limits": {
        "type": "object",
        "properties": {
         "l": {
          "type": "number",
          "minimum": 0
         },
         "w": {
          "type": "number",
          "minimum": 0
         },
         "h": {
          "type": "number",
          "minimum": 0
         },
         "kg": {
          "type": "number",
          "minimum": 0
         },
         "sum": {
          "type": "number",
          "minimum": 0
         },
         "girth": {
          "type": "number",
          "minimum": 0
         },
         "longest": {
          "type": "number",
          "minimum": 0
         },
         "kg_min": {
          "type": "number",
          "minimum": 0
         },
         "vol_div": {
          "type": "number",
          "minimum": 1
         }
        },
        "required": [
         "kg"
        ],
        "additionalProperties": false,
        "description": "centimetres and kilograms; l/w/h a box the parcel must fit in any orientation; sum = l+w+h; girth = longest + 2 × (the other two); kg_min the least a service takes; vol_div: the kg limit applies to the greater of the real weight and l×w×h ÷ vol_div (volumetric weight)"
       },
       "how": {
        "type": "object",
        "properties": {
         "url": {
          "type": "string",
          "pattern": "^https://",
          "description": "a public https page"
         },
         "steps": {
          "type": "array",
          "items": {
           "type": "string"
          }
         }
        },
        "required": [
         "url",
         "steps"
        ],
        "additionalProperties": false
       },
       "source": {
        "type": "string",
        "pattern": "^https://",
        "description": "a public https page"
       },
       "checked": {
        "type": "string",
        "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
        "description": "YYYY-MM-DD"
       },
       "stale": {
        "type": "boolean"
       },
       "note": {
        "type": "string"
       }
      },
      "required": [
       "carrier",
       "carrier_id",
       "country",
       "town",
       "price",
       "fits",
       "why",
       "limits",
       "how",
       "source",
       "checked",
       "stale",
       "note"
      ],
      "additionalProperties": false
     },
     "description": "same town to same town: couriers that price only in their own app — no number, by design"
    }
   },
   "required": [
    "ok",
    "version",
    "region",
    "lang",
    "checked",
    "stale",
    "from",
    "to",
    "parcel",
    "verdict",
    "options",
    "cheapest",
    "fastest",
    "in_app"
   ],
   "additionalProperties": false
  },
  {
   "type": "object",
   "properties": {
    "ok": {
     "const": false
    },
    "error": {
     "type": "string",
     "enum": [
      "from_unknown",
      "to_unknown",
      "no_carriers",
      "size_missing",
      "size_bad",
      "slow_down",
      "not_found",
      "method",
      "server"
     ]
    },
    "region": {
     "type": "string"
    },
    "regions": {
     "type": "array",
     "items": {
      "type": "string"
     }
    },
    "from": {
     "type": "object",
     "properties": {
      "country": {
       "type": "string",
       "pattern": "^[A-Z]{2}$",
       "description": "ISO 3166-1 alpha-2"
      },
      "town": {
       "type": [
        "string",
        "null"
       ]
      },
      "postcode": {
       "type": [
        "string",
        "null"
       ]
      }
     },
     "required": [
      "country",
      "town",
      "postcode"
     ],
     "additionalProperties": false
    },
    "to": {
     "type": "object",
     "properties": {
      "country": {
       "type": "string",
       "pattern": "^[A-Z]{2}$",
       "description": "ISO 3166-1 alpha-2"
      },
      "town": {
       "type": [
        "string",
        "null"
       ]
      },
      "postcode": {
       "type": [
        "string",
        "null"
       ]
      }
     },
     "required": [
      "country",
      "town",
      "postcode"
     ],
     "additionalProperties": false
    },
    "retry_after": {
     "type": "integer",
     "minimum": 1
    }
   },
   "required": [
    "ok",
    "error"
   ],
   "additionalProperties": false
  }
 ]
}