{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:vera:patent-box:ledger-selection",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "format",
    "sheet",
    "header_row",
    "first_row",
    "last_row",
    "delimiter",
    "encoding",
    "pdf_extraction"
  ],
  "properties": {
    "format": {
      "enum": [
        "CSV",
        "XLSX",
        "PDF"
      ]
    },
    "sheet": {
      "anyOf": [
        {
          "type": "string",
          "minLength": 1,
          "maxLength": 10000
        },
        {
          "type": "null"
        }
      ]
    },
    "header_row": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 1,
          "maximum": 100000
        },
        {
          "type": "null"
        }
      ]
    },
    "first_row": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 1,
          "maximum": 100000
        },
        {
          "type": "null"
        }
      ]
    },
    "last_row": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 1,
          "maximum": 100000
        },
        {
          "type": "null"
        }
      ]
    },
    "delimiter": {
      "anyOf": [
        {
          "enum": [
            ",",
            ";",
            "\t"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "encoding": {
      "anyOf": [
        {
          "enum": [
            "utf-8",
            "utf-8-sig",
            "cp1252"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "pdf_extraction": {
      "anyOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "columns",
            "rows",
            "rationale"
          ],
          "properties": {
            "columns": {
              "type": "array",
              "minItems": 1,
              "maxItems": 500,
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "column_id",
                  "label"
                ],
                "properties": {
                  "column_id": {
                    "type": "string",
                    "pattern": "[A-Z]{1,3}"
                  },
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 10000
                  }
                }
              }
            },
            "rows": {
              "type": "array",
              "minItems": 1,
              "maxItems": 100000,
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "page",
                  "quote",
                  "cells"
                ],
                "properties": {
                  "page": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000
                  },
                  "quote": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 10000
                  },
                  "cells": {
                    "type": "object"
                  }
                }
              }
            },
            "rationale": {
              "type": "string",
              "minLength": 1,
              "maxLength": 10000
            }
          }
        },
        {
          "type": "null"
        }
      ]
    }
  }
}
