{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "supplier": {
      "type": "object",
      "properties": {
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "address": {
          "type": [
            "string",
            "null"
          ]
        },
        "tax_id": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "name",
        "address",
        "tax_id"
      ],
      "additionalProperties": false
    },
    "customer": {
      "type": "object",
      "properties": {
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "address": {
          "type": [
            "string",
            "null"
          ]
        },
        "tax_id": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "name",
        "address",
        "tax_id"
      ],
      "additionalProperties": false
    },
    "invoice_number": {
      "type": [
        "string",
        "null"
      ]
    },
    "issue_date": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        {
          "type": "null"
        }
      ]
    },
    "due_date": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        {
          "type": "null"
        }
      ]
    },
    "currency": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        {
          "type": "null"
        }
      ]
    },
    "subtotal": {
      "type": [
        "number",
        "null"
      ]
    },
    "tax_lines": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "label": {
            "type": [
              "string",
              "null"
            ]
          },
          "rate": {
            "type": [
              "number",
              "null"
            ]
          },
          "amount": {
            "type": [
              "number",
              "null"
            ]
          }
        },
        "required": [
          "label",
          "rate",
          "amount"
        ],
        "additionalProperties": false
      }
    },
    "tax": {
      "type": [
        "number",
        "null"
      ]
    },
    "withholding": {
      "type": [
        "number",
        "null"
      ]
    },
    "total": {
      "type": [
        "number",
        "null"
      ]
    },
    "line_items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "quantity": {
            "type": [
              "number",
              "null"
            ]
          },
          "unit_price": {
            "type": [
              "number",
              "null"
            ]
          },
          "amount": {
            "type": [
              "number",
              "null"
            ]
          }
        },
        "required": [
          "description",
          "quantity",
          "unit_price",
          "amount"
        ],
        "additionalProperties": false
      }
    },
    "checks": {
      "type": "object",
      "properties": {
        "values_found": {
          "type": "object",
          "properties": {
            "passed": {
              "type": "boolean",
              "description": "True when every value the model read is in the document"
            },
            "removed": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "description": "Values the model read that the document’s words don’t hold, by path (`customer.tax_id`, `line_items[2].amount`): each is null in the output"
            }
          },
          "required": [
            "passed",
            "removed"
          ],
          "additionalProperties": false,
          "description": "Every value must be found in the document’s own words"
        },
        "line_items_add_up": {
          "type": "object",
          "properties": {
            "passed": {
              "description": "Whether the sum holds; null when a figure it needs is missing",
              "type": [
                "boolean",
                "null"
              ]
            },
            "sum": {
              "type": [
                "number",
                "null"
              ]
            },
            "subtotal": {
              "type": [
                "number",
                "null"
              ]
            }
          },
          "required": [
            "passed",
            "sum",
            "subtotal"
          ],
          "additionalProperties": false,
          "description": "The line items’ amounts against the subtotal"
        },
        "tax_lines_add_up": {
          "type": "object",
          "properties": {
            "passed": {
              "description": "Whether the sum holds; null when a figure it needs is missing",
              "type": [
                "boolean",
                "null"
              ]
            },
            "sum": {
              "type": [
                "number",
                "null"
              ]
            },
            "tax": {
              "type": [
                "number",
                "null"
              ]
            }
          },
          "required": [
            "passed",
            "sum",
            "tax"
          ],
          "additionalProperties": false,
          "description": "The tax lines’ amounts against the tax"
        },
        "total_adds_up": {
          "type": "object",
          "properties": {
            "passed": {
              "description": "Whether the sum holds; null when a figure it needs is missing",
              "type": [
                "boolean",
                "null"
              ]
            },
            "expected": {
              "type": [
                "number",
                "null"
              ]
            },
            "total": {
              "type": [
                "number",
                "null"
              ]
            }
          },
          "required": [
            "passed",
            "expected",
            "total"
          ],
          "additionalProperties": false,
          "description": "The subtotal and tax, less any withholding, against the total"
        }
      },
      "required": [
        "values_found",
        "line_items_add_up",
        "tax_lines_add_up",
        "total_adds_up"
      ],
      "additionalProperties": false,
      "description": "What we checked: values are never changed, only removed when they aren’t found"
    }
  },
  "required": [
    "supplier",
    "customer",
    "invoice_number",
    "issue_date",
    "due_date",
    "currency",
    "subtotal",
    "tax_lines",
    "tax",
    "withholding",
    "total",
    "line_items",
    "checks"
  ],
  "additionalProperties": false
}
