{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/jithox-com/json-schema/jithox-com-invoice-review-response-schema.json",
  "title": "InvoiceReviewResponse",
  "x-generated": "2026-10-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/jithox-com-openapi.json#/components/schemas/InvoiceReviewResponse",
  "type": "object",
  "properties": {
    "review": {
      "$ref": "#/$defs/InvoiceReview"
    },
    "verified": {
      "type": "boolean",
      "description": "Whether a VAT number was sent to the EU VIES register on this run, whatever it answered. False when nothing was sent: signed out, not enough credits, no VAT number on the invoice, or a number the lookup refused before the register."
    },
    "register": {
      "type": "object",
      "properties": {
        "ran": {
          "type": "boolean",
          "description": "The same fact as verified: a VAT number was sent to the EU VIES register on this run."
        },
        "notRunBecause": {
          "enum": [
            "signed_out",
            "insufficient_credits",
            "nothing_to_look_up",
            null
          ],
          "description": "Why the register was not asked, as a value to branch on; null when it ran. nothing_to_look_up: the invoice has no VAT number the lookup could take (none, or every one refused before the register), so neither signing in nor topping up would get the register asked."
        }
      },
      "required": [
        "ran",
        "notRunBecause"
      ],
      "additionalProperties": false
    },
    "billing": {
      "type": "object",
      "properties": {
        "charged": {
          "type": "boolean"
        },
        "credits": {
          "type": "integer",
          "minimum": 0
        },
        "reason": {
          "type": "string"
        },
        "receiptRunId": {
          "type": "string",
          "description": "The id of the credit-ledger booking. A reference, not a signed receipt."
        },
        "balanceAfter": {
          "type": "number"
        }
      },
      "required": [
        "charged",
        "credits",
        "reason"
      ],
      "additionalProperties": false
    },
    "pricing": {
      "type": "object",
      "properties": {
        "localChecks": {
          "const": "included"
        },
        "registerCheck": {
          "type": "string"
        },
        "toolCredits": {
          "type": "integer",
          "minimum": 0
        },
        "note": {
          "type": "string"
        }
      },
      "required": [
        "localChecks",
        "registerCheck",
        "toolCredits",
        "note"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "review",
    "verified",
    "register",
    "billing",
    "pricing"
  ],
  "additionalProperties": false,
  "$defs": {
    "InvoiceReview": {
      "type": "object",
      "properties": {
        "inputFormat": {
          "const": "structured_invoice"
        },
        "invoiceNumber": {
          "type": [
            "string",
            "null"
          ]
        },
        "next_checks": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "tool": {
                "const": "check_peppol_ready"
              },
              "reason": {
                "type": "string"
              }
            },
            "required": [
              "tool",
              "reason"
            ],
            "additionalProperties": false
          },
          "description": "Suggested receiver check, not executed by this review; present when the invoice has a lookupable receiver address."
        },
        "checks": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/InvoiceReviewCheck"
          }
        },
        "findings": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/InvoiceReviewFinding"
          }
        },
        "readyToSend": {
          "type": "boolean",
          "description": "No blocker, and the Peppol export was built and parses."
        },
        "hasUnknowns": {
          "type": "boolean",
          "description": "A check could not reach a verdict, or a VAT number was not checked against the register."
        },
        "totals": {
          "oneOf": [
            {
              "$ref": "#/$defs/InvoiceReviewTotals"
            },
            {
              "type": "null"
            }
          ]
        },
        "draft": {
          "oneOf": [
            {
              "type": "object",
              "description": "A draft message. Nothing has been sent.",
              "properties": {
                "kind": {
                  "const": "email_draft"
                },
                "to": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "subject": {
                  "type": "string"
                },
                "body": {
                  "type": "string"
                }
              },
              "required": [
                "kind",
                "to",
                "subject",
                "body"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        },
        "export": {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "filename": {
                  "type": "string"
                },
                "mediaType": {
                  "const": "application/xml"
                },
                "ubl": {
                  "type": "string",
                  "description": "UBL 2.1 / Peppol BIS Billing 3.0."
                }
              },
              "required": [
                "filename",
                "mediaType",
                "ubl"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "inputFormat",
        "invoiceNumber",
        "checks",
        "findings",
        "readyToSend",
        "hasUnknowns",
        "totals",
        "draft",
        "export"
      ],
      "additionalProperties": false
    },
    "InvoiceReviewCheck": {
      "type": "object",
      "properties": {
        "id": {
          "enum": [
            "structure",
            "arithmetic",
            "payment_details",
            "supplier_vat",
            "customer_vat",
            "peppol",
            "peppol_receiver"
          ]
        },
        "label": {
          "type": "string"
        },
        "status": {
          "enum": [
            "pass",
            "fail",
            "unknown",
            "skipped"
          ],
          "description": "skipped means the check did not run; it is never a pass."
        },
        "source": {
          "enum": [
            "local",
            "eu_vies",
            "peppol_sml"
          ]
        },
        "detail": {
          "type": "string"
        },
        "consultationNumber": {
          "type": "string",
          "description": "The European Commission's own number for this VIES consultation, on a passed VAT check when a requester is configured."
        },
        "consultationRequester": {
          "type": "string"
        },
        "consultationAt": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "label",
        "status",
        "source",
        "detail"
      ],
      "additionalProperties": false
    },
    "InvoiceReviewFinding": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "severity": {
          "enum": [
            "blocker",
            "warning",
            "info"
          ],
          "description": "A blocker stops sending."
        },
        "field": {
          "type": "string",
          "description": "Dotted path into the input, when the finding belongs to one field."
        },
        "what": {
          "type": "string"
        },
        "fix": {
          "type": "string"
        },
        "rule": {
          "type": "string",
          "description": "The Peppol / EN 16931 rule id, when the finding comes from that rule set."
        }
      },
      "required": [
        "code",
        "severity",
        "what",
        "fix"
      ],
      "additionalProperties": false
    },
    "InvoiceReviewTotals": {
      "type": "object",
      "properties": {
        "currency": {
          "type": "string"
        },
        "lineExtensionAmount": {
          "type": "string"
        },
        "taxExclusiveAmount": {
          "type": "string"
        },
        "taxAmount": {
          "type": "string"
        },
        "taxInclusiveAmount": {
          "type": "string"
        },
        "payableAmount": {
          "type": "string"
        },
        "taxSubtotals": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "taxCategory": {
                "type": "string"
              },
              "percent": {
                "type": "number"
              },
              "taxableAmount": {
                "type": "string"
              },
              "taxAmount": {
                "type": "string"
              }
            },
            "required": [
              "taxCategory",
              "percent",
              "taxableAmount",
              "taxAmount"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "currency",
        "lineExtensionAmount",
        "taxExclusiveAmount",
        "taxAmount",
        "taxInclusiveAmount",
        "payableAmount",
        "taxSubtotals"
      ],
      "additionalProperties": false
    }
  }
}