{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://blackproof.fr/schemas/source-import/v1.schema.json",
  "title": "BLACKPROOF XLSX source import sidecar V1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "formatVersion",
    "caseId",
    "sourceQuestionnaire",
    "profile",
    "sourceFormat",
    "selectedSheet",
    "selectedColumn",
    "formulaCount",
    "formulaWithoutCachedValueCount",
    "hiddenSheetCount",
    "externalLinkPartCount",
    "externalRelationshipCount",
    "connectionPartCount",
    "queryTablePartCount",
    "warnings",
    "questionSources",
    "ignoredFormulaCells"
  ],
  "properties": {
    "formatVersion": {
      "const": "blackproof-source-import-v1"
    },
    "caseId": {
      "type": "string",
      "minLength": 1
    },
    "sourceQuestionnaire": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "fileName",
        "format",
        "importedAt",
        "sha256",
        "originalFileSha256",
        "size"
      ],
      "properties": {
        "fileName": {
          "type": "string",
          "pattern": "\\.[xX][lL][sS][xX]$"
        },
        "format": {
          "const": "unknown"
        },
        "importedAt": {
          "type": "string",
          "format": "date-time"
        },
        "sha256": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        },
        "normalizedQuestionnaireSha256": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        },
        "originalFileSha256": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        },
        "canonicalizationVersion": {
          "enum": [
            "blackproof-questionnaire-canonicalization-v1",
            "blackproof-questionnaire-canonicalization-v2"
          ]
        },
        "size": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "profile": {
      "const": "blackproof-xlsx-import-v1"
    },
    "sourceFormat": {
      "const": "xlsx"
    },
    "selectedSheet": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "selectedColumn": {
      "type": "integer",
      "minimum": 1,
      "maximum": 100
    },
    "selectedColumnName": {
      "type": "string",
      "maxLength": 10000
    },
    "formulaCount": {
      "$ref": "#/$defs/boundedCount"
    },
    "formulaWithoutCachedValueCount": {
      "$ref": "#/$defs/boundedCount"
    },
    "hiddenSheetCount": {
      "type": "integer",
      "minimum": 0,
      "maximum": 10
    },
    "externalLinkPartCount": {
      "type": "integer",
      "minimum": 0,
      "maximum": 256
    },
    "externalRelationshipCount": {
      "$ref": "#/$defs/boundedCount"
    },
    "connectionPartCount": {
      "type": "integer",
      "minimum": 0,
      "maximum": 256
    },
    "queryTablePartCount": {
      "type": "integer",
      "minimum": 0,
      "maximum": 256
    },
    "warnings": {
      "type": "array",
      "maxItems": 100,
      "items": {
        "type": "string",
        "maxLength": 1000
      }
    },
    "questionSources": {
      "type": "array",
      "minItems": 1,
      "maxItems": 250,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "question",
          "source",
          "cellReference"
        ],
        "properties": {
          "question": {
            "type": "string",
            "minLength": 1,
            "maxLength": 10000
          },
          "source": {
            "enum": [
              "literal-cell",
              "cached-formula-value"
            ]
          },
          "cellReference": {
            "$ref": "#/$defs/cellReference"
          }
        }
      }
    },
    "ignoredFormulaCells": {
      "type": "array",
      "maxItems": 500000,
      "items": {
        "$ref": "#/$defs/cellReference"
      }
    }
  },
  "$defs": {
    "boundedCount": {
      "type": "integer",
      "minimum": 0,
      "maximum": 500000
    },
    "cellReference": {
      "type": "string",
      "pattern": "^[A-Z]{1,3}[1-9][0-9]*$"
    }
  }
}