{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.deeta.app/deeta-file-standard/deeta-import-v1.report.schema.json",
  "title": "Deeta import report, format major 1",
  "description": "What Import & Merge found wrong with a file, or left out of an import. It holds locations and codes, never values.",
  "type": "object",
  "required": ["reportVersion", "reportId", "totals", "truncated", "entries"],
  "additionalProperties": false,
  "properties": {
    "reportVersion": { "const": "1" },
    "reportId": { "type": "string", "pattern": "^RPT-[0-9A-Z]{8}$" },
    "formatVersion": { "oneOf": [{ "type": "null" }, { "type": "string", "maxLength": 40 }] },
    "totals": {
      "type": "object",
      "required": ["file_fatal", "row_rejected", "row_skipped"],
      "additionalProperties": false,
      "properties": {
        "file_fatal": { "type": "integer", "minimum": 0 },
        "row_rejected": { "type": "integer", "minimum": 0 },
        "row_skipped": { "type": "integer", "minimum": 0 }
      }
    },
    "truncated": { "type": "boolean" },
    "entries": { "type": "array", "maxItems": 500, "items": { "$ref": "#/$defs/entry" } }
  },
  "$defs": {
    "entry": {
      "type": "object",
      "required": ["code", "severity", "collection", "rowIndex", "rowId", "field", "message"],
      "additionalProperties": false,
      "properties": {
        "code": { "$ref": "#/$defs/code" },
        "severity": { "enum": ["file_fatal", "row_rejected", "row_skipped"] },
        "collection": {
          "oneOf": [
            { "type": "null" },
            {
              "enum": [
                "contacts",
                "deets",
                "tags",
                "contact_tag_ids",
                "groups",
                "group_members",
                "self_profile",
                "self_deets",
                "deet_sets",
                "relationships"
              ]
            }
          ]
        },
        "rowIndex": { "oneOf": [{ "type": "null" }, { "type": "integer", "minimum": 0 }] },
        "rowId": {
          "oneOf": [
            { "type": "null" },
            { "type": "string", "pattern": "^(new(:[A-Za-z0-9_-]{1,64})?|[0-9a-fA-F-]{36})$" }
          ]
        },
        "field": { "oneOf": [{ "type": "null" }, { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_.\\[\\]]{0,99}$" }] },
        "message": { "type": "string", "maxLength": 300 }
      }
    },
    "code": {
      "enum": [
        "invalid_json",
        "not_a_deeta_file",
        "unsupported_format",
        "missing_format_version",
        "invalid_format_version",
        "newer_format_version",
        "older_format_version",
        "file_too_large",
        "is_backup_file",
        "relationships_not_supported",
        "no_rows",

        "unknown_field",
        "missing_field",
        "wrong_type",
        "null_value",
        "invalid_value",
        "invalid_id",
        "missing_import_type",
        "import_type_on_new_row",
        "unknown_import_type",

        "duplicate_local_key",
        "undeclared_local_key",
        "duplicate_row_id",
        "duplicate_target",
        "orphan_row",
        "parent_not_found",
        "parent_cycle",
        "nesting_too_deep",
        "duplicate_core_field_label",
        "membership_under_update",
        "self_rows_without_profile",

        "string_empty",
        "string_too_long",
        "forbidden_character",
        "invalid_birthday",

        "over_file_cap",
        "over_account_cap",

        "uuid_not_found",
        "type_mismatch",
        "ambiguous_match",

        "already_present",
        "not_present",
        "late_constraint"
      ]
    }
  }
}
