{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Generic API Message",
  "description": "A message for the generic CHI Cargo API",
  "type": "object",
  "definitions": {
    "mawb_number": {
      "type": "string",
      "title": "mawb_number",
      "description": "Master Airway Bill Number",
      "examples": [
        "58461598740"
      ],
      "pattern": "^([\\d]{11})$"
    },
    "hawb_number": {
      "type": "string",
      "title": "hawb_number",
      "description": "House Airway Bill Number",
      "minLength": 1,
      "pattern": "^[A-Z0-9]+$",
      "examples": [
        "FRA123456"
      ]
    },
    "manifest_number": {
      "type": "string",
      "title": "manifest_number",
      "description": "Manifest Number",
      "minLength": 1,
      "examples": [
        "FRA123456"
      ],
      "pattern": "^([A-Z0-9]+)$"
    },
    "additional_data": {
      "type": "object",
      "title": "additional_data",
      "description": "Arbitrary data that the customer can define by himself. This data is not visible in Chicargo and will be returned in all status messages. Use case is for example: Cargo Wise One ID´s"
    },
    "timestamp": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "examples": [
        "2018-12-27T20:00:00+01:00"
      ]
    },
    "origin_destination": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^[A-Z0-9]{3}$",
      "examples": [
        "FRA",
        "MUC"
      ]
    },
    "consolidation_type": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "consol",
        "b2b",
        "iata_direct"
      ],
      "default": "consol"
    },
    "pieces": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 1
    },
    "weight": {
      "type": [
        "number",
        "null"
      ],
      "minimum": 0.1
    },
    "dimension": {
      "type": "integer",
      "description": "Length in centimeters",
      "minimum": 1
    },
    "hazard_class": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "nonhazardous",
        "explosive",
        "gas",
        "flammable_liquid",
        "flammable_solid",
        "oxidizing_substance",
        "toxic_and_infectious_substance",
        "radioactive_material",
        "corrosive",
        "miscellaneous_dangerous_good",
        "lithium_batteries",
        "unknown"
      ],
      "default": "nonhazardous"
    },
    "ssccs": {
      "type": [
        "array",
        "null"
      ],
      "title": "sscc",
      "description": "Serial shipping container code",
      "items": {
        "type": "string",
        "minLength": 18,
        "maxLength": 18
      }
    },
    "package_references": {
      "type": [
        "array",
        "null"
      ],
      "title": "pack_refs",
      "description": "Alternative package references for customer use",
      "items": {
        "type": "string"
      }
    },
    "process_type": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "inbound",
        "outbound"
      ]
    },
    "alt_refs": {
      "type": [
        "string",
        "null"
      ]
    },
    "consigner": {
      "type": [
        "string",
        "null"
      ]
    },
    "consignee": {
      "type": [
        "string",
        "null"
      ]
    },
    "content": {
      "type": [
        "string",
        "null"
      ]
    },
    "measurements": {
      "title": "measurements",
      "description": "Measurements for each piece on shipment",
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "length",
          "width",
          "height"
        ],
        "properties": {
          "length": {
            "$ref": "#/definitions/dimension"
          },
          "width": {
            "$ref": "#/definitions/dimension"
          },
          "height": {
            "$ref": "#/definitions/dimension"
          },
          "weight": {
            "$ref": "#/definitions/weight"
          }
        }
      }
    }
  },
  "properties": {
    "data": {
      "additionalProperties": false,
      "properties": {
        "inbound_masters": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "mawb_number"
            ],
            "properties": {
              "mawb_number": {
                "$ref": "#/definitions/mawb_number"
              },
              "consolidation_type": {
                "$ref": "#/definitions/consolidation_type"
              },
              "origin": {
                "$ref": "#/definitions/origin_destination"
              },
              "destination": {
                "$ref": "#/definitions/origin_destination"
              },
              "pieces": {
                "$ref": "#/definitions/pieces"
              },
              "weight": {
                "$ref": "#/definitions/weight"
              },
              "total_amount_of_parts": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 1
              },
              "eta": {
                "$ref": "#/definitions/timestamp"
              },
              "alt_refs": {
                "$ref": "#/definitions/alt_refs"
              },
              "additional_data": {
                "$ref": "#/definitions/additional_data"
              }
            }
          }
        },
        "outbound_masters": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "mawb_number"
            ],
            "properties": {
              "mawb_number": {
                "$ref": "#/definitions/mawb_number"
              },
              "consolidation_type": {
                "$ref": "#/definitions/consolidation_type"
              },
              "origin": {
                "$ref": "#/definitions/origin_destination"
              },
              "destination": {
                "$ref": "#/definitions/origin_destination"
              },
              "lat": {
                "$ref": "#/definitions/timestamp"
              },
              "contour": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "pieces": {
                "$ref": "#/definitions/pieces"
              },
              "weight": {
                "$ref": "#/definitions/weight"
              },
              "alt_refs": {
                "$ref": "#/definitions/alt_refs"
              },
              "additional_data": {
                "$ref": "#/definitions/additional_data"
              }
            }
          }
        },
        "inbound_shipments": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "hawb_number"
            ],
            "properties": {
              "hawb_number": {
                "$ref": "#/definitions/hawb_number"
              },
              "pieces": {
                "$ref": "#/definitions/pieces"
              },
              "weight": {
                "$ref": "#/definitions/weight"
              },
              "origin": {
                "$ref": "#/definitions/origin_destination"
              },
              "destination": {
                "$ref": "#/definitions/origin_destination"
              },
              "alt_refs": {
                "$ref": "#/definitions/alt_refs"
              },
              "consigner": {
                "$ref": "#/definitions/consigner"
              },
              "consignee": {
                "$ref": "#/definitions/consignee"
              },
              "content": {
                "$ref": "#/definitions/content"
              },
              "hazard_class": {
                "$ref": "#/definitions/hazard_class"
              },
              "measurements": {
                "$ref": "#/definitions/measurements"
              },
              "ssccs": {
                "$ref": "#/definitions/ssccs"
              },
              "package_references": {
                "$ref": "#/definitions/package_references"
              },
              "additional_data": {
                "$ref": "#/definitions/additional_data"
              }
            }
          }
        },
        "outbound_shipments": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "anyOf": [
              {
                "required": [
                  "hawb_number"
                ]
              },
              {
                "required": [
                  "alt_refs"
                ]
              }
            ],
            "properties": {
              "hawb_number": {
                "$ref": "#/definitions/hawb_number"
              },
              "prior_party_secured": {
                "type": "boolean"
              },
              "origin": {
                "$ref": "#/definitions/origin_destination"
              },
              "destination": {
                "$ref": "#/definitions/origin_destination"
              },
              "pieces": {
                "$ref": "#/definitions/pieces"
              },
              "weight": {
                "$ref": "#/definitions/weight"
              },
              "alt_refs": {
                "$ref": "#/definitions/alt_refs"
              },
              "consigner": {
                "$ref": "#/definitions/consigner"
              },
              "consignee": {
                "$ref": "#/definitions/consignee"
              },
              "content": {
                "$ref": "#/definitions/content"
              },
              "hazard_class": {
                "$ref": "#/definitions/hazard_class"
              },
              "subawb_number": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "measurements": {
                "$ref": "#/definitions/measurements"
              },
              "ssccs": {
                "$ref": "#/definitions/ssccs"
              },
              "package_references": {
                "$ref": "#/definitions/package_references"
              },
              "piece_references": {
                "$ref": "#/definitions/package_references"
              },
              "additional_data": {
                "$ref": "#/definitions/additional_data"
              }
            }
          }
        },
        "inbound_pickups": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "manifest_number"
            ],
            "properties": {
              "manifest_number": {
                "$ref": "#/definitions/manifest_number"
              },
              "announced_for": {
                "$ref": "#/definitions/timestamp"
              },
              "station": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "license_plate": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "phone": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "trucker": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "hauler": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        },
        "outbound_arrivals": {
          "$ref": "#/properties/data/properties/inbound_pickups"
        },
        "inbound_arrivals": {
          "$ref": "#/properties/data/properties/inbound_pickups"
        }
      },
      "type": "object"
    },
    "actions": {
      "additionalProperties": false,
      "properties": {
        "attach_shipment": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "hawb_number": {
                "$ref": "#/definitions/hawb_number"
              },
              "process_type": {
                "$ref": "#/definitions/process_type"
              },
              "mawb_number": {
                "$ref": "#/definitions/mawb_number"
              },
              "manifest_number": {
                "$ref": "#/definitions/manifest_number"
              }
            },
            "required": [
              "hawb_number",
              "process_type"
            ],
            "oneOf": [
              {
                "required": [
                  "mawb_number"
                ]
              },
              {
                "required": [
                  "manifest_number"
                ]
              }
            ]
          }
        },
        "detach_shipment": {
          "$ref": "#/properties/actions/properties/attach_shipment"
        },
        "attach_shipment_to_arrival": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "hawb_number": {
                "$ref": "#/definitions/hawb_number"
              },
              "process_type": {
                "$ref": "#/definitions/process_type"
              },
              "manifest_number": {
                "$ref": "#/definitions/manifest_number"
              }
            },
            "required": [
              "hawb_number",
              "process_type",
              "manifest_number"
            ]
          }
        },
        "cancel": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "hawb_number": {
                "$ref": "#/definitions/hawb_number"
              },
              "mawb_number": {
                "$ref": "#/definitions/mawb_number"
              },
              "manifest_number": {
                "$ref": "#/definitions/manifest_number"
              },
              "process_type": {
                "$ref": "#/definitions/process_type"
              }
            },
            "required": [
              "process_type"
            ],
            "oneOf": [
              {
                "required": [
                  "mawb_number"
                ]
              },
              {
                "required": [
                  "manifest_number"
                ]
              },
              {
                "required": [
                  "hawb_number"
                ]
              }
            ]
          }
        },
        "add_work_item": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "hawb_number": {
                "$ref": "#/definitions/hawb_number"
              },
              "process_type": {
                "$ref": "#/definitions/process_type"
              },
              "mawb_number": {
                "$ref": "#/definitions/mawb_number"
              },
              "workable": {
                "type": "string"
              },
              "instructions": {
                "type": "string"
              },
              "client_reference": {
                "type": "string"
              },
              "attach_shipments": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "alt_refs": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "alt_refs"
                  ]
                }
              }
            },
            "required": [
              "workable",
              "process_type"
            ],
            "allOf": [
              {
                "oneOf": [
                  {
                    "required": [
                      "mawb_number"
                    ]
                  },
                  {
                    "required": [
                      "hawb_number"
                    ]
                  }
                ]
              },
              {
                "if": {
                  "properties": {
                    "workable": {
                      "const": "label_hawb"
                    }
                  }
                },
                "else": {
                  "not": {
                    "required": [
                      "attach_shipments"
                    ]
                  }
                }
              },
              {
                "if": {
                  "properties": {
                    "process_type": {
                      "const": "outbound"
                    }
                  },
                  "required": [
                    "hawb_number"
                  ]
                },
                "then": {
                  "properties": {
                    "workable": {
                      "enum": [
                        "secure",
                        "palletize",
                        "measure",
                        "neutralize",
                        "label_hawb",
                        "shrink",
                        "weigh",
                        "photograph",
                        "other"
                      ]
                    }
                  }
                },
                "else": {
                  "properties": {
                    "workable": {
                      "enum": [
                        "palletize",
                        "measure",
                        "neutralize",
                        "shrink",
                        "weigh",
                        "photograph",
                        "other"
                      ]
                    }
                  }
                }
              }
            ]
          }
        }
      },
      "type": "object"
    }
  }
}
