{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openbusinesstrust.eu/schema/receipt/v0.json",
  "title": "OBT Compliance Receipt v0: the claims after disclosure processing",
  "description": "Normative (OBT Part 3, Annex A.1). Validates the claims a checker holds after it has verified the issuer-signed JWT and replaced each disclosed digest by its member (RFC 9901 clause 7.1). A member the holder did not disclose is absent. Cross-member rules (the sum rule, line coverage, iat = nbf, the exp rule) are in clause 5 and are not expressible here.",
  "type": "object",
  "required": [
    "vct",
    "vct#integrity",
    "jti",
    "iat",
    "nbf",
    "exp",
    "status",
    "rev_id",
    "document",
    "seller",
    "buyer",
    "decisions",
    "assurance",
    "code_lists"
  ],
  "additionalProperties": false,
  "patternProperties": {
    "^[a-z]{2}$": {
      "$ref": "#/$defs/countryBlock"
    }
  },
  "properties": {
    "iss": {
      "$ref": "#/$defs/httpsUrl"
    },
    "iss_reg_id": {
      "$ref": "#/$defs/issuerId"
    },
    "vct": {
      "const": "https://openbusinesstrust.eu/vct/receipt/v0"
    },
    "vct#integrity": {
      "$ref": "#/$defs/sri"
    },
    "jti": {
      "$ref": "#/$defs/randomId"
    },
    "replaces": {
      "$ref": "#/$defs/randomId"
    },
    "iat": {
      "$ref": "#/$defs/numericDate"
    },
    "nbf": {
      "$ref": "#/$defs/numericDate"
    },
    "exp": {
      "$ref": "#/$defs/numericDate"
    },
    "status": {
      "type": "object",
      "required": [
        "status_list"
      ],
      "additionalProperties": false,
      "properties": {
        "status_list": {
          "type": "object",
          "required": [
            "idx",
            "uri"
          ],
          "additionalProperties": false,
          "properties": {
            "idx": {
              "$ref": "#/$defs/index"
            },
            "uri": {
              "$ref": "#/$defs/httpsUrl"
            }
          }
        }
      }
    },
    "rev_id": {
      "type": "string",
      "pattern": "^[1-9][0-9]{0,19}$"
    },
    "document": {
      "type": "object",
      "required": [
        "type",
        "number",
        "issue_date",
        "currency",
        "net",
        "vat",
        "gross",
        "source",
        "address",
        "line_count"
      ],
      "additionalProperties": false,
      "properties": {
        "type": {
          "enum": [
            "380",
            "381",
            "383",
            "386"
          ]
        },
        "number": {
          "$ref": "#/$defs/documentNumber"
        },
        "issue_date": {
          "$ref": "#/$defs/date"
        },
        "supply_date": {
          "$ref": "#/$defs/date"
        },
        "supply_period": {
          "type": "object",
          "required": [
            "start",
            "end"
          ],
          "additionalProperties": false,
          "properties": {
            "start": {
              "$ref": "#/$defs/date"
            },
            "end": {
              "$ref": "#/$defs/date"
            }
          }
        },
        "currency": {
          "$ref": "#/$defs/currency"
        },
        "net": {
          "$ref": "#/$defs/money"
        },
        "vat": {
          "$ref": "#/$defs/money"
        },
        "gross": {
          "$ref": "#/$defs/money"
        },
        "vat_national": {
          "type": "object",
          "required": [
            "currency",
            "amount",
            "fx_rate",
            "fx_rate_date"
          ],
          "additionalProperties": false,
          "properties": {
            "currency": {
              "$ref": "#/$defs/currency"
            },
            "amount": {
              "$ref": "#/$defs/money"
            },
            "fx_rate": {
              "type": "string",
              "pattern": "^(0|[1-9][0-9]{0,9})\\.[0-9]{1,10}$"
            },
            "fx_rate_date": {
              "$ref": "#/$defs/date"
            }
          }
        },
        "file_sha256": {
          "$ref": "#/$defs/hex256"
        },
        "gobl": {
          "type": "object",
          "required": [
            "uuid",
            "dig"
          ],
          "additionalProperties": false,
          "properties": {
            "uuid": {
              "type": "string",
              "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
            },
            "dig": {
              "type": "object",
              "required": [
                "alg",
                "val"
              ],
              "additionalProperties": false,
              "properties": {
                "alg": {
                  "const": "sha256"
                },
                "val": {
                  "$ref": "#/$defs/hex256"
                }
              }
            }
          }
        },
        "source": {
          "const": "issued_by_issuer"
        },
        "address": {
          "$ref": "#/$defs/httpsUrl"
        },
        "preceding": {
          "type": "array",
          "minItems": 1,
          "maxItems": 32,
          "items": {
            "type": "object",
            "required": [
              "number",
              "issue_date"
            ],
            "additionalProperties": false,
            "properties": {
              "number": {
                "$ref": "#/$defs/documentNumber"
              },
              "issue_date": {
                "$ref": "#/$defs/date"
              },
              "address": {
                "$ref": "#/$defs/httpsUrl"
              }
            }
          }
        },
        "line_count": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000
        },
        "deliver_to_country": {
          "$ref": "#/$defs/country"
        },
        "einvoices": {
          "type": "array",
          "minItems": 1,
          "maxItems": 4,
          "items": {
            "type": "object",
            "required": [
              "sha256",
              "syntax",
              "specification"
            ],
            "additionalProperties": false,
            "properties": {
              "sha256": {
                "$ref": "#/$defs/hex256"
              },
              "syntax": {
                "enum": [
                  "ubl-2.1",
                  "cii-d16b"
                ]
              },
              "specification": {
                "$ref": "#/$defs/einvoiceContext"
              },
              "process": {
                "$ref": "#/$defs/einvoiceContext"
              }
            }
          }
        },
        "chargeable_date": {
          "$ref": "#/$defs/date"
        },
        "cash_accounting": {
          "const": true
        },
        "simplified": {
          "const": true
        }
      },
      "oneOf": [
        {
          "required": [
            "supply_date"
          ],
          "not": {
            "required": [
              "supply_period"
            ]
          }
        },
        {
          "required": [
            "supply_period"
          ],
          "not": {
            "required": [
              "supply_date"
            ]
          }
        }
      ],
      "anyOf": [
        {
          "required": [
            "file_sha256"
          ]
        },
        {
          "required": [
            "gobl"
          ]
        },
        {
          "required": [
            "einvoices"
          ]
        }
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "381",
                  "383"
                ]
              }
            }
          },
          "then": {
            "required": [
              "preceding"
            ]
          }
        }
      ]
    },
    "seller": {
      "type": "object",
      "required": [
        "country",
        "vat_id_on_document"
      ],
      "additionalProperties": false,
      "properties": {
        "country": {
          "$ref": "#/$defs/country"
        },
        "tax_id": {
          "$ref": "#/$defs/taxId"
        },
        "vat_id_on_document": {
          "type": "boolean"
        }
      }
    },
    "buyer": {
      "type": "object",
      "required": [
        "country",
        "is_business",
        "vat_id_on_document"
      ],
      "additionalProperties": false,
      "properties": {
        "country": {
          "$ref": "#/$defs/country"
        },
        "establishment_country": {
          "$ref": "#/$defs/country"
        },
        "is_business": {
          "type": "boolean"
        },
        "business_proof": {
          "enum": [
            "vies_confirmed",
            "vies_number_valid",
            "other_proof",
            "non_eu_tax_certificate",
            "non_eu_tax_number",
            "customer_word"
          ]
        },
        "tax_id": {
          "$ref": "#/$defs/taxId"
        },
        "vat_id_on_document": {
          "type": "boolean"
        }
      },
      "if": {
        "properties": {
          "is_business": {
            "const": true
          }
        }
      },
      "then": {
        "required": [
          "business_proof"
        ]
      },
      "else": {
        "not": {
          "required": [
            "business_proof"
          ]
        }
      }
    },
    "made_by": {
      "type": "object",
      "required": [
        "kind",
        "app",
        "may_issue"
      ],
      "additionalProperties": false,
      "properties": {
        "kind": {
          "const": "connected_app"
        },
        "app": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{3,64}$"
        },
        "may_issue": {
          "const": true
        }
      }
    },
    "decisions": {
      "type": "array",
      "minItems": 1,
      "maxItems": 256,
      "items": {
        "$ref": "#/$defs/decision"
      },
      "contains": {
        "required": [
          "lines"
        ]
      }
    },
    "withholding": {
      "type": "object",
      "required": [
        "applies",
        "known_at"
      ],
      "additionalProperties": false,
      "patternProperties": {
        "^(?!by$)[a-z]{2}$": {
          "$ref": "#/$defs/countryBlock"
        }
      },
      "properties": {
        "applies": {
          "type": "boolean"
        },
        "known_at": {
          "const": "issue"
        },
        "rate": {
          "$ref": "#/$defs/rate"
        },
        "base": {
          "$ref": "#/$defs/money"
        },
        "amount": {
          "$ref": "#/$defs/money"
        },
        "by": {
          "const": "customer"
        }
      },
      "if": {
        "properties": {
          "applies": {
            "const": true
          }
        }
      },
      "then": {
        "required": [
          "rate",
          "base",
          "amount",
          "by"
        ]
      },
      "else": {
        "allOf": [
          {
            "not": {
              "required": [
                "rate"
              ]
            }
          },
          {
            "not": {
              "required": [
                "amount"
              ]
            }
          },
          {
            "not": {
              "required": [
                "base"
              ]
            }
          },
          {
            "not": {
              "required": [
                "by"
              ]
            }
          }
        ]
      }
    },
    "checks": {
      "type": "array",
      "minItems": 1,
      "maxItems": 16,
      "items": {
        "$ref": "#/$defs/check"
      }
    },
    "report": {
      "type": "array",
      "minItems": 1,
      "maxItems": 4,
      "items": {
        "type": "object",
        "required": [
          "to",
          "regime",
          "by",
          "result",
          "time"
        ],
        "additionalProperties": false,
        "properties": {
          "to": {
            "type": "string",
            "pattern": "^[A-Z]{2}-[A-Z]{2,8}$"
          },
          "regime": {
            "type": "string",
            "pattern": "^[A-Z]{2}-[A-Z0-9]{2,12}$"
          },
          "by": {
            "const": "issuer"
          },
          "result": {
            "const": "accepted"
          },
          "time": {
            "$ref": "#/$defs/utcTime"
          }
        }
      }
    },
    "assurance": {
      "type": "object",
      "required": [
        "treatment",
        "terms",
        "terms#integrity"
      ],
      "additionalProperties": false,
      "properties": {
        "treatment": {
          "enum": [
            "correct",
            "provisional"
          ]
        },
        "terms": {
          "$ref": "#/$defs/httpsUrl"
        },
        "terms#integrity": {
          "$ref": "#/$defs/sri"
        }
      }
    },
    "code_lists": {
      "type": "object",
      "required": [
        "en16931"
      ],
      "additionalProperties": false,
      "properties": {
        "en16931": {
          "type": "string",
          "pattern": "^v[0-9]{1,3}[a-z]?$"
        }
      }
    }
  },
  "$defs": {
    "httpsUrl": {
      "type": "string",
      "maxLength": 256,
      "pattern": "^https://[A-Za-z0-9.-]+(:[0-9]{1,5})?(/[A-Za-z0-9._~%!$&'()*+,;=:@-]*)*$"
    },
    "sri": {
      "type": "string",
      "pattern": "^sha256-[A-Za-z0-9+/]{43}=$"
    },
    "randomId": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]{22,64}$"
    },
    "numericDate": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "index": {
      "type": "integer",
      "minimum": 0,
      "maximum": 4294967295
    },
    "date": {
      "type": "string",
      "pattern": "^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$"
    },
    "utcTime": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
    },
    "currency": {
      "type": "string",
      "pattern": "^[A-Z]{3}$"
    },
    "country": {
      "type": "string",
      "pattern": "^[A-Z]{2}$"
    },
    "money": {
      "type": "string",
      "pattern": "^(0\\.00|-?(0\\.(0[1-9]|[1-9][0-9])|[1-9][0-9]{0,14}\\.[0-9]{2}))$"
    },
    "rate": {
      "type": "string",
      "pattern": "^(100|[1-9]?[0-9](\\.[0-9]{0,2}[1-9])?)$"
    },
    "hex256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "taxId": {
      "type": "string",
      "pattern": "^[A-Z]{2}[0-9A-Z+*]{2,15}$"
    },
    "safeText": {
      "type": "string",
      "pattern": "^[\\p{L}\\p{N} .,;:()/ºª°%+'_\\u2013-]{1,120}$"
    },
    "countryBlock": {
      "type": "object",
      "minProperties": 1,
      "maxProperties": 16,
      "propertyNames": {
        "pattern": "^[a-z][a-z0-9_]{0,31}$"
      },
      "additionalProperties": {
        "oneOf": [
          {
            "$ref": "#/$defs/safeText"
          },
          {
            "type": "boolean"
          },
          {
            "type": "integer"
          }
        ]
      }
    },
    "lineRanges": {
      "oneOf": [
        {
          "const": "all"
        },
        {
          "type": "array",
          "minItems": 1,
          "maxItems": 512,
          "items": {
            "type": "array",
            "minItems": 2,
            "maxItems": 2,
            "items": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000000
            }
          }
        }
      ]
    },
    "decision": {
      "type": "object",
      "required": [
        "net",
        "vat",
        "place_of_supply",
        "treatment",
        "liability",
        "vat_category",
        "law",
        "basis",
        "engine"
      ],
      "additionalProperties": false,
      "patternProperties": {
        "^[a-z]{2}$": {
          "$ref": "#/$defs/countryBlock"
        }
      },
      "properties": {
        "lines": {
          "$ref": "#/$defs/lineRanges"
        },
        "charge": {
          "type": "integer",
          "minimum": 1,
          "maximum": 999
        },
        "allowance": {
          "type": "integer",
          "minimum": 1,
          "maximum": 999
        },
        "net": {
          "$ref": "#/$defs/money"
        },
        "place_of_supply": {
          "type": "object",
          "required": [
            "country",
            "rule"
          ],
          "additionalProperties": false,
          "properties": {
            "country": {
              "$ref": "#/$defs/country"
            },
            "region": {
              "type": "string",
              "pattern": "^[a-z0-9_]{2,32}$"
            },
            "rule": {
              "enum": [
                "ancillary_transport",
                "cultural_activity",
                "deemed_supplier",
                "electronic_service",
                "energy_via_network",
                "event_admission_physical",
                "event_virtual",
                "facilitation_service",
                "general_service",
                "goods",
                "goods_chain_transport",
                "goods_distance_sale_imported",
                "goods_distance_sale_intra_eu",
                "goods_installed",
                "goods_on_board",
                "goods_transport",
                "goods_transport_intra_eu",
                "immovable_property",
                "immovable_property_transfer",
                "intermediary",
                "listed_service_non_eu_consumer",
                "passenger_transport",
                "restaurant_catering",
                "restaurant_catering_on_board",
                "transport_hire",
                "travel_agent_margin",
                "use_and_enjoyment",
                "work_on_movable_property"
              ]
            },
            "below_union_threshold": {
              "const": true
            },
            "location_evidence": {
              "type": "object",
              "required": [
                "kinds",
                "count"
              ],
              "additionalProperties": false,
              "properties": {
                "kinds": {
                  "type": "array",
                  "minItems": 1,
                  "maxItems": 7,
                  "uniqueItems": true,
                  "items": {
                    "enum": [
                      "billing_address",
                      "ip_geolocation",
                      "bank_location",
                      "mobile_country_code",
                      "fixed_line_location",
                      "other_commercial",
                      "decoder_or_viewing_card"
                    ]
                  }
                },
                "count": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 20
                },
                "presumption": {
                  "enum": [
                    "art_24a",
                    "art_24b_a",
                    "art_24b_b",
                    "art_24b_c",
                    "art_24b_d"
                  ]
                }
              }
            }
          }
        },
        "scheme": {
          "enum": [
            "oss_union",
            "oss_non_union",
            "ioss",
            "margin_scheme",
            "sme",
            "sme_cross_border"
          ]
        },
        "treatment": {
          "enum": [
            "taxable",
            "exempt_no_credit",
            "zero_rated_credit",
            "out_of_scope"
          ]
        },
        "liability": {
          "type": "object",
          "required": [
            "who"
          ],
          "additionalProperties": false,
          "properties": {
            "who": {
              "enum": [
                "supplier",
                "customer",
                "none"
              ]
            },
            "basis": {
              "enum": [
                "art_194",
                "art_195",
                "art_196",
                "art_197",
                "art_198",
                "art_199",
                "art_199a",
                "art_199b",
                "art_395"
              ]
            }
          },
          "if": {
            "properties": {
              "who": {
                "const": "customer"
              }
            }
          },
          "then": {
            "required": [
              "basis"
            ]
          },
          "else": {
            "not": {
              "required": [
                "basis"
              ]
            }
          }
        },
        "conditions": {
          "type": "array",
          "minItems": 1,
          "maxItems": 2,
          "uniqueItems": true,
          "items": {
            "enum": [
              "proof_of_exit_pending",
              "proof_of_transport_pending"
            ]
          }
        },
        "rate": {
          "$ref": "#/$defs/rate"
        },
        "vat_category": {
          "enum": [
            "S",
            "Z",
            "E",
            "AE",
            "K",
            "G",
            "O",
            "L",
            "M"
          ]
        },
        "vatex": {
          "type": "string",
          "pattern": "^VATEX-[A-Z]{2}-[0-9A-Z/-]{1,24}$"
        },
        "law": {
          "type": "array",
          "minItems": 1,
          "maxItems": 8,
          "items": {
            "type": "object",
            "required": [
              "act",
              "article"
            ],
            "additionalProperties": false,
            "properties": {
              "act": {
                "type": "string",
                "pattern": "^(http://data\\.europa\\.eu/eli/(dir|reg|reg_impl|dec|dec_impl)/[0-9]{4}/[0-9]{1,5}/oj|[A-Z]{2}-[A-Z0-9-]{2,24})$"
              },
              "article": {
                "type": "string",
                "pattern": "^[\\p{L}\\p{N} .,()ºª°/-]{1,48}$"
              },
              "reading": {
                "const": "a_contrario"
              },
              "consolidation": {
                "type": "string",
                "pattern": "^0[0-9]{4}[A-Z][0-9]{4}-[0-9]{8}$"
              },
              "ref": {
                "type": "string",
                "maxLength": 300,
                "pattern": "^(?:[a-z]{2}(?:-[a-z0-9]{1,3})?|int):[a-z0-9][^\\s]*$"
              }
            }
          }
        },
        "basis": {
          "type": "object",
          "required": [
            "facts"
          ],
          "additionalProperties": false,
          "properties": {
            "rate": {
              "enum": [
                "national_list_item",
                "national_provision",
                "official_product_code",
                "engine_product_code",
                "standard_default",
                "seller_stated_tier",
                "standard_residual",
                "assumed_default"
              ]
            },
            "facts": {
              "type": "array",
              "maxItems": 9,
              "items": {
                "type": "object",
                "required": [
                  "kind",
                  "source"
                ],
                "additionalProperties": false,
                "properties": {
                  "kind": {
                    "enum": [
                      "seller_establishment",
                      "seller_registration",
                      "seller_qualification",
                      "buyer_taxable_status",
                      "buyer_qualification",
                      "buyer_location",
                      "supply_location",
                      "supply_nature",
                      "supply_condition"
                    ]
                  },
                  "source": {
                    "enum": [
                      "checked",
                      "evidenced",
                      "seller_stated",
                      "buyer_stated",
                      "assumed"
                    ]
                  }
                }
              }
            }
          }
        },
        "engine": {
          "type": "object",
          "required": [
            "id",
            "version",
            "data",
            "decision_id",
            "inputs_commitment"
          ],
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9-]{1,62}$"
            },
            "version": {
              "type": "string",
              "pattern": "^[0-9A-Za-z.+-]{1,32}$"
            },
            "data": {
              "type": "string",
              "pattern": "^[\\x21-\\x7E]{1,512}$"
            },
            "decision_id": {
              "$ref": "#/$defs/randomId"
            },
            "inputs_commitment": {
              "type": "string",
              "pattern": "^hmac-sha256:[A-Za-z0-9_-]{43}$"
            }
          }
        },
        "vat": {
          "$ref": "#/$defs/money"
        }
      },
      "oneOf": [
        {
          "required": [
            "lines"
          ],
          "not": {
            "anyOf": [
              {
                "required": [
                  "charge"
                ]
              },
              {
                "required": [
                  "allowance"
                ]
              }
            ]
          }
        },
        {
          "required": [
            "charge"
          ],
          "not": {
            "anyOf": [
              {
                "required": [
                  "lines"
                ]
              },
              {
                "required": [
                  "allowance"
                ]
              }
            ]
          }
        },
        {
          "required": [
            "allowance"
          ],
          "not": {
            "anyOf": [
              {
                "required": [
                  "lines"
                ]
              },
              {
                "required": [
                  "charge"
                ]
              }
            ]
          }
        }
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "vat_category": {
                "const": "O"
              }
            }
          },
          "then": {
            "not": {
              "required": [
                "rate"
              ]
            }
          },
          "else": {
            "required": [
              "rate"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "vat_category": {
                "enum": [
                  "Z",
                  "E",
                  "AE",
                  "K",
                  "G"
                ]
              }
            }
          },
          "then": {
            "properties": {
              "rate": {
                "const": "0"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "vat_category": {
                "const": "S"
              }
            }
          },
          "then": {
            "properties": {
              "rate": {
                "not": {
                  "const": "0"
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "vat_category": {
                "enum": [
                  "L",
                  "M"
                ]
              }
            }
          },
          "then": {
            "properties": {
              "place_of_supply": {
                "properties": {
                  "country": {
                    "const": "ES"
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "vat_category": {
                "enum": [
                  "S",
                  "Z",
                  "L",
                  "M"
                ]
              }
            }
          },
          "then": {
            "not": {
              "required": [
                "vatex"
              ]
            },
            "patternProperties": {
              "^[a-z]{2}$": {
                "not": {
                  "required": [
                    "mention"
                  ]
                }
              }
            }
          }
        },
        {
          "if": {
            "required": [
              "vatex"
            ],
            "properties": {
              "vatex": {
                "const": "VATEX-EU-AE"
              }
            }
          },
          "then": {
            "properties": {
              "vat_category": {
                "const": "AE"
              }
            }
          }
        },
        {
          "if": {
            "required": [
              "vatex"
            ],
            "properties": {
              "vatex": {
                "const": "VATEX-EU-IC"
              }
            }
          },
          "then": {
            "properties": {
              "vat_category": {
                "const": "K"
              }
            }
          }
        },
        {
          "if": {
            "required": [
              "vatex"
            ],
            "properties": {
              "vatex": {
                "const": "VATEX-EU-G"
              }
            }
          },
          "then": {
            "properties": {
              "vat_category": {
                "const": "G"
              }
            }
          }
        },
        {
          "if": {
            "required": [
              "vatex"
            ],
            "properties": {
              "vatex": {
                "const": "VATEX-EU-O"
              }
            }
          },
          "then": {
            "properties": {
              "vat_category": {
                "const": "O"
              }
            }
          }
        },
        {
          "if": {
            "required": [
              "vatex"
            ],
            "properties": {
              "vatex": {
                "enum": [
                  "VATEX-EU-D",
                  "VATEX-EU-F",
                  "VATEX-EU-I",
                  "VATEX-EU-J"
                ]
              }
            }
          },
          "then": {
            "properties": {
              "vat_category": {
                "const": "E"
              }
            }
          }
        },
        {
          "if": {
            "required": [
              "vatex"
            ],
            "properties": {
              "vatex": {
                "pattern": "^VATEX-EU-(79-C|13[25]|14[3468]|15[139]|309)"
              }
            }
          },
          "then": {
            "properties": {
              "vat_category": {
                "const": "E"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "vat_category": {
                "const": "AE"
              }
            }
          },
          "then": {
            "properties": {
              "liability": {
                "properties": {
                  "who": {
                    "const": "customer"
                  }
                }
              }
            }
          },
          "else": {
            "properties": {
              "liability": {
                "properties": {
                  "who": {
                    "enum": [
                      "supplier",
                      "none"
                    ]
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "place_of_supply": {
                "required": [
                  "below_union_threshold"
                ]
              }
            }
          },
          "then": {
            "properties": {
              "place_of_supply": {
                "properties": {
                  "rule": {
                    "enum": [
                      "electronic_service",
                      "goods_distance_sale_intra_eu"
                    ]
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "scheme": {
                "const": "margin_scheme"
              }
            },
            "required": [
              "scheme"
            ]
          },
          "then": {
            "required": [
              "vatex"
            ],
            "properties": {
              "vat_category": {
                "const": "E"
              },
              "vatex": {
                "enum": [
                  "VATEX-EU-D",
                  "VATEX-EU-F",
                  "VATEX-EU-I",
                  "VATEX-EU-J"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "scheme": {
                "enum": [
                  "sme",
                  "sme_cross_border"
                ]
              }
            },
            "required": [
              "scheme"
            ]
          },
          "then": {
            "properties": {
              "vat_category": {
                "const": "E"
              },
              "treatment": {
                "const": "exempt_no_credit"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "place_of_supply": {
                "required": [
                  "below_union_threshold"
                ]
              }
            },
            "required": [
              "scheme"
            ]
          },
          "then": {
            "properties": {
              "scheme": {
                "not": {
                  "const": "oss_union"
                }
              }
            }
          }
        }
      ]
    },
    "vatNumberResult": {
      "type": "object",
      "required": [
        "number"
      ],
      "additionalProperties": false,
      "properties": {
        "number": {
          "enum": [
            "valid",
            "invalid",
            "unavailable"
          ]
        },
        "name_address": {
          "enum": [
            "confirmed",
            "not_confirmed",
            "not_returned"
          ]
        }
      },
      "if": {
        "properties": {
          "number": {
            "const": "unavailable"
          }
        }
      },
      "then": {
        "not": {
          "required": [
            "name_address"
          ]
        }
      },
      "else": {
        "required": [
          "name_address"
        ]
      }
    },
    "provenance": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "kind"
          ],
          "additionalProperties": false,
          "properties": {
            "kind": {
              "const": "stated"
            }
          }
        },
        {
          "type": "object",
          "required": [
            "kind",
            "tee",
            "measurement",
            "code",
            "measurements_url",
            "attestation_url"
          ],
          "additionalProperties": false,
          "properties": {
            "kind": {
              "const": "tee_attested"
            },
            "tee": {
              "enum": [
                "aws-nitro",
                "intel-tdx",
                "amd-sev-snp"
              ]
            },
            "measurement": {
              "type": "string",
              "pattern": "^[0-9a-f]{64,128}$"
            },
            "code": {
              "type": "object",
              "required": [
                "repository",
                "commit"
              ],
              "additionalProperties": false,
              "properties": {
                "repository": {
                  "$ref": "#/$defs/httpsUrl"
                },
                "commit": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{40}([0-9a-f]{24})?$"
                }
              }
            },
            "measurements_url": {
              "$ref": "#/$defs/httpsUrl"
            },
            "attestation_url": {
              "$ref": "#/$defs/httpsUrl"
            }
          }
        }
      ]
    },
    "check": {
      "type": "object",
      "required": [
        "what",
        "source",
        "result",
        "time",
        "by"
      ],
      "additionalProperties": false,
      "properties": {
        "what": {
          "enum": [
            "buyer_vat_number",
            "buyer_withholds",
            "app_may_issue"
          ]
        },
        "source": {
          "enum": [
            "VIES",
            "HMRC",
            "ISSUER"
          ]
        },
        "result": {
          "oneOf": [
            {
              "$ref": "#/$defs/vatNumberResult"
            },
            {
              "enum": [
                "valid",
                "invalid",
                "withholds",
                "does_not_withhold",
                "unavailable"
              ]
            }
          ]
        },
        "time": {
          "$ref": "#/$defs/utcTime"
        },
        "by": {
          "$ref": "#/$defs/issuerId"
        },
        "proof_digest": {
          "type": "string",
          "pattern": "^blinded-sha256:[A-Za-z0-9_-]{43}$"
        },
        "provenance": {
          "$ref": "#/$defs/provenance"
        },
        "reference": {
          "type": "string",
          "pattern": "^[A-Za-z0-9]{1,32}$"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "what": {
                "const": "buyer_vat_number"
              }
            }
          },
          "then": {
            "properties": {
              "source": {
                "enum": [
                  "VIES",
                  "HMRC"
                ]
              },
              "result": {
                "$ref": "#/$defs/vatNumberResult"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "what": {
                "const": "app_may_issue"
              }
            }
          },
          "then": {
            "properties": {
              "source": {
                "const": "ISSUER"
              },
              "result": {
                "enum": [
                  "valid",
                  "invalid"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "what": {
                "const": "buyer_withholds"
              }
            }
          },
          "then": {
            "properties": {
              "result": {
                "enum": [
                  "withholds",
                  "does_not_withhold",
                  "unavailable"
                ]
              },
              "source": {
                "const": "ISSUER"
              }
            }
          }
        }
      ]
    },
    "documentNumber": {
      "type": "string",
      "maxLength": 64,
      "pattern": "^[A-Za-z0-9._/-]+( [A-Za-z0-9._/-]+)*$"
    },
    "issuerId": {
      "type": "string",
      "pattern": "^VAT[A-Z]{2}-[0-9A-Z+*]{2,15}$"
    },
    "einvoiceContext": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "pattern": "^[^\\u0000-\\u0020\\u007F](?:[^\\u0000-\\u001F\\u007F]*[^\\u0000-\\u0020\\u007F])?$"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "buyer": {
            "properties": {
              "business_proof": {
                "const": "customer_word"
              }
            },
            "required": [
              "business_proof"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "assurance": {
            "properties": {
              "treatment": {
                "const": "provisional"
              }
            }
          }
        }
      }
    }
  ]
}
