{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://kaldenframelabs.com/schemas/tabular-shape-receipt-v1.schema.json",
  "title": "KaldenFrame Tabular Shape Receipt v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "tool",
    "version",
    "release_status",
    "label",
    "source",
    "limits",
    "shape_sha256",
    "shape",
    "boundaries"
  ],
  "properties": {
    "schema": {"const": "kaldenframe.tabular-shape-receipt.receipt.v1"},
    "tool": {"const": "Tabular Shape Receipt"},
    "version": {"type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"},
    "release_status": {"const": "COMMERCIAL_RELEASE"},
    "label": {"type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$"},
    "source": {"$ref": "#/$defs/source"},
    "limits": {"$ref": "#/$defs/limits"},
    "shape_sha256": {"$ref": "#/$defs/sha256"},
    "shape": {"$ref": "#/$defs/shape"},
    "boundaries": {"$ref": "#/$defs/boundaries"}
  },
  "$defs": {
    "sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
    "columnName": {
      "type": "string",
      "minLength": 1,
      "pattern": "^[^\\u0000-\\u001f\\u007f]+$"
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "format", "bytes", "sha256", "utf8_bom", "newline_style"],
      "properties": {
        "name": {"type": "string", "minLength": 1, "pattern": "^[^/\\\\\\u0000-\\u001f\\u007f]+$"},
        "format": {"enum": ["csv", "jsonl"]},
        "bytes": {"type": "integer", "minimum": 0},
        "sha256": {"$ref": "#/$defs/sha256"},
        "utf8_bom": {"type": "boolean"},
        "newline_style": {"enum": ["NONE", "CRLF", "LF", "CR", "MIXED"]}
      }
    },
    "limits": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "max_bytes",
        "max_rows",
        "max_columns",
        "max_field_chars",
        "max_record_chars",
        "max_distinct_row_hashes"
      ],
      "properties": {
        "max_bytes": {"type": "integer", "minimum": 1, "maximum": 100000000000},
        "max_rows": {"type": "integer", "minimum": 1, "maximum": 100000000},
        "max_columns": {"type": "integer", "minimum": 1, "maximum": 100000},
        "max_field_chars": {"type": "integer", "minimum": 1, "maximum": 100000000},
        "max_record_chars": {"type": "integer", "minimum": 1, "maximum": 500000000},
        "max_distinct_row_hashes": {"type": "integer", "minimum": 1, "maximum": 10000000}
      }
    },
    "csvParsing": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "format",
        "delimiter",
        "quote",
        "header",
        "null_markers",
        "naive_datetime_timezone",
        "aware_datetime_timezone"
      ],
      "properties": {
        "format": {"const": "csv"},
        "delimiter": {"type": "string", "minLength": 1, "maxLength": 1},
        "quote": {"const": "\""},
        "header": {"const": true},
        "null_markers": {
          "type": "array",
          "maxItems": 128,
          "uniqueItems": true,
          "items": {"type": "string", "minLength": 1, "maxLength": 1024}
        },
        "naive_datetime_timezone": {"const": "UTC_ASSUMED"},
        "aware_datetime_timezone": {"const": "UTC_NORMALIZED"}
      }
    },
    "jsonlParsing": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "format",
        "duplicate_keys_rejected",
        "naive_datetime_timezone",
        "aware_datetime_timezone"
      ],
      "properties": {
        "format": {"const": "jsonl"},
        "duplicate_keys_rejected": {"const": true},
        "naive_datetime_timezone": {"const": "UTC_ASSUMED"},
        "aware_datetime_timezone": {"const": "UTC_NORMALIZED"}
      }
    },
    "rows": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "data_rows",
        "blank_input_lines",
        "shape_error_rows",
        "extra_field_count",
        "distinct_row_hashes",
        "duplicate_rows",
        "duplicate_groups"
      ],
      "properties": {
        "data_rows": {"type": "integer", "minimum": 0},
        "blank_input_lines": {"type": "integer", "minimum": 0},
        "shape_error_rows": {"type": "integer", "minimum": 0},
        "extra_field_count": {"type": "integer", "minimum": 0},
        "distinct_row_hashes": {"type": "integer", "minimum": 0},
        "duplicate_rows": {"type": "integer", "minimum": 0},
        "duplicate_groups": {"type": "integer", "minimum": 0}
      }
    },
    "typeCounts": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "missing": {"type": "integer", "minimum": 0},
        "null": {"type": "integer", "minimum": 0},
        "blank": {"type": "integer", "minimum": 0},
        "boolean": {"type": "integer", "minimum": 0},
        "integer": {"type": "integer", "minimum": 0},
        "number": {"type": "integer", "minimum": 0},
        "date": {"type": "integer", "minimum": 0},
        "datetime": {"type": "integer", "minimum": 0},
        "string": {"type": "integer", "minimum": 0},
        "array": {"type": "integer", "minimum": 0},
        "object": {"type": "integer", "minimum": 0}
      }
    },
    "timestampGrid": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "parseable_count",
        "monotonic_non_decreasing",
        "positive_interval_count",
        "zero_interval_count",
        "negative_interval_count",
        "positive_intervals",
        "interval_set_truncated"
      ],
      "properties": {
        "parseable_count": {"type": "integer", "minimum": 0},
        "monotonic_non_decreasing": {"type": ["boolean", "null"]},
        "positive_interval_count": {"type": "integer", "minimum": 0},
        "zero_interval_count": {"type": "integer", "minimum": 0},
        "negative_interval_count": {"type": "integer", "minimum": 0},
        "positive_intervals": {
          "type": "array",
          "maxItems": 64,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["seconds", "occurrences"],
            "properties": {
              "seconds": {"type": "number", "exclusiveMinimum": 0},
              "occurrences": {"type": "integer", "minimum": 1}
            }
          }
        },
        "interval_set_truncated": {"type": "boolean"}
      }
    },
    "column": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "ordinal", "type_counts", "timestamp_grid"],
      "properties": {
        "name": {"$ref": "#/$defs/columnName"},
        "ordinal": {"type": "integer", "minimum": 0},
        "type_counts": {"$ref": "#/$defs/typeCounts"},
        "timestamp_grid": {"$ref": "#/$defs/timestampGrid"}
      }
    },
    "shape": {
      "type": "object",
      "additionalProperties": false,
      "required": ["parsing", "rows", "columns", "ordered_columns"],
      "properties": {
        "parsing": {"oneOf": [{"$ref": "#/$defs/csvParsing"}, {"$ref": "#/$defs/jsonlParsing"}]},
        "rows": {"$ref": "#/$defs/rows"},
        "columns": {"type": "array", "items": {"$ref": "#/$defs/column"}},
        "ordered_columns": {
          "type": "array",
          "uniqueItems": true,
          "items": {"$ref": "#/$defs/columnName"}
        }
      }
    },
    "boundaries": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "network_requested",
        "source_modified",
        "absolute_path_recorded",
        "raw_row_value_recorded",
        "sample_value_recorded",
        "minimum_or_maximum_recorded",
        "quantile_or_frequency_value_recorded",
        "provenance_proved",
        "completeness_proved",
        "semantic_correctness_proved",
        "distribution_stability_proved",
        "absence_of_leakage_proved",
        "security_safety_compliance_or_fitness_proved"
      ],
      "properties": {
        "network_requested": {"const": false},
        "source_modified": {"const": false},
        "absolute_path_recorded": {"const": false},
        "raw_row_value_recorded": {"const": false},
        "sample_value_recorded": {"const": false},
        "minimum_or_maximum_recorded": {"const": false},
        "quantile_or_frequency_value_recorded": {"const": false},
        "provenance_proved": {"const": false},
        "completeness_proved": {"const": false},
        "semantic_correctness_proved": {"const": false},
        "distribution_stability_proved": {"const": false},
        "absence_of_leakage_proved": {"const": false},
        "security_safety_compliance_or_fitness_proved": {"const": false}
      }
    }
  }
}
