{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://botlandscape.com/compare.schema.json",
  "title": "Bot Landscape compact comparison index",
  "type": "object",
  "additionalProperties": false,
  "required": ["$schema", "schema_version", "source_schema_version", "counts", "tables", "profiles", "sources"],
  "properties": {
    "$schema": {"const": "https://botlandscape.com/compare.schema.json"},
    "schema_version": {"const": 3},
    "source_schema_version": {"type": "integer", "minimum": 1},
    "counts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["tables", "rows", "claims", "sources", "profiles", "profile_metrics", "profile_claims"],
      "properties": {
        "tables": {"type": "integer", "minimum": 0},
        "rows": {"type": "integer", "minimum": 0},
        "claims": {"type": "integer", "minimum": 0},
        "sources": {"type": "integer", "minimum": 0},
        "profiles": {"type": "integer", "minimum": 0},
        "profile_metrics": {"type": "integer", "minimum": 0},
        "profile_claims": {"type": "integer", "minimum": 0}
      }
    },
    "tables": {"type": "array", "items": {"$ref": "#/$defs/table"}},
    "profiles": {"type": "array", "items": {"$ref": "#/$defs/profile"}},
    "sources": {"type": "array", "items": {"$ref": "#/$defs/source"}}
  },
  "$defs": {
    "link": {
      "type": "object",
      "additionalProperties": false,
      "required": ["text", "url"],
      "properties": {
        "text": {"type": "string"},
        "url": {"type": "string", "format": "uri"}
      }
    },
    "cell": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "column", "subject_ids", "state", "text", "evidence", "links"],
      "properties": {
        "id": {"type": "string", "minLength": 1},
        "column": {"type": "integer", "minimum": 0},
        "subject_ids": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"type": "string", "pattern": "^[a-z0-9]+(?:-+[a-z0-9]+)*$"}},
        "state": {"enum": ["reported", "missing"]},
        "text": {"type": "string"},
        "evidence": {"type": "array", "uniqueItems": true, "items": {"type": "string"}},
        "links": {"type": "array", "items": {"$ref": "#/$defs/link"}}
      }
    },
    "row": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "metric", "url", "cells"],
      "properties": {
        "id": {"type": "string", "minLength": 1},
        "metric": {"type": "string", "minLength": 1},
        "url": {"type": "string", "format": "uri"},
        "cells": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/cell"}}
      }
    },
    "table": {
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "page_path", "id", "class", "label", "caption", "subjects", "rows"],
      "properties": {
        "key": {"type": "string", "minLength": 1},
        "page_path": {"type": "string", "pattern": "\\.html$"},
        "id": {"type": "string", "minLength": 1},
        "class": {"type": "string", "minLength": 1},
        "label": {"type": "string", "minLength": 1},
        "caption": {"type": "string", "minLength": 1},
        "subjects": {"type": "array", "uniqueItems": true, "items": {"$ref": "#/$defs/subject"}},
        "rows": {"type": "array", "items": {"$ref": "#/$defs/row"}}
      }
    },
    "subject": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label"],
      "properties": {
        "id": {"type": "string", "pattern": "^[a-z0-9]+(?:-+[a-z0-9]+)*$"},
        "label": {"type": "string", "minLength": 1},
        "entity_id": {"type": "string", "pattern": "^[a-z0-9]+(?:-+[a-z0-9]+)*$"}
      }
    },
    "profile_subject": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "origin_keys"],
      "properties": {
        "id": {"type": "string", "pattern": "^[a-z0-9]+(?:-+[a-z0-9]+)*$"},
        "label": {"type": "string", "minLength": 1},
        "entity_id": {"type": "string", "pattern": "^[a-z0-9]+(?:-+[a-z0-9]+)*$"},
        "origin_keys": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"type": "string", "minLength": 1}}
      }
    },
    "profile_origin": {
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "page_path", "table_id", "label", "caption"],
      "properties": {
        "key": {"type": "string", "minLength": 1},
        "page_path": {"type": "string", "pattern": "\\.html$"},
        "table_id": {"type": "string", "minLength": 1},
        "label": {"type": "string", "minLength": 1},
        "caption": {"type": "string", "minLength": 1}
      }
    },
    "profile_cell": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "subject_ids", "state", "text", "evidence", "links", "claim_url"],
      "properties": {
        "id": {"type": "string", "minLength": 1},
        "subject_ids": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"type": "string", "pattern": "^[a-z0-9]+(?:-+[a-z0-9]+)*$"}},
        "state": {"enum": ["reported", "missing"]},
        "text": {"type": "string"},
        "evidence": {"type": "array", "uniqueItems": true, "items": {"type": "string"}},
        "links": {"type": "array", "items": {"$ref": "#/$defs/link"}},
        "claim_url": {"type": "string", "format": "uri"}
      }
    },
    "profile_row": {
      "type": "object",
      "additionalProperties": false,
      "required": ["table_key", "row_id", "source_metric", "url", "cells"],
      "properties": {
        "table_key": {"type": "string", "minLength": 1},
        "row_id": {"type": "string", "minLength": 1},
        "source_metric": {"type": "string", "minLength": 1},
        "url": {"type": "string", "format": "uri"},
        "cells": {"type": "array", "items": {"$ref": "#/$defs/profile_cell"}}
      }
    },
    "profile_metric": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "definition", "unit_family", "rows"],
      "properties": {
        "id": {"type": "string", "pattern": "^[a-z0-9]+(?:-+[a-z0-9]+)*$"},
        "label": {"type": "string", "minLength": 1},
        "definition": {"type": "string", "minLength": 1},
        "unit_family": {"type": ["string", "null"]},
        "rows": {"type": "array", "minItems": 2, "items": {"$ref": "#/$defs/profile_row"}}
      }
    },
    "profile_exclusion": {
      "type": "object",
      "additionalProperties": false,
      "required": ["subject_id", "reason"],
      "properties": {
        "subject_id": {"type": "string", "pattern": "^[a-z0-9]+(?:-+[a-z0-9]+)*$"},
        "reason": {"type": "string", "minLength": 1}
      }
    },
    "profile": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "class", "label", "boundary", "origins", "subjects", "metrics", "subject_exclusions"],
      "properties": {
        "id": {"type": "string", "pattern": "^[a-z0-9]+(?:-+[a-z0-9]+)*$"},
        "class": {"type": "string", "minLength": 1},
        "label": {"type": "string", "minLength": 1},
        "boundary": {"type": "string", "minLength": 1},
        "origins": {"type": "array", "minItems": 2, "items": {"$ref": "#/$defs/profile_origin"}},
        "subjects": {"type": "array", "items": {"$ref": "#/$defs/profile_subject"}},
        "metrics": {"type": "array", "minItems": 3, "items": {"$ref": "#/$defs/profile_metric"}},
        "subject_exclusions": {"type": "array", "uniqueItems": true, "items": {"$ref": "#/$defs/profile_exclusion"}}
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "marker", "grade", "citation", "access_status", "registry_url", "direct_url"],
      "properties": {
        "id": {"type": "string", "pattern": "^[a-z0-9-]+-[mfapr][0-9]+$"},
        "marker": {"type": "string", "pattern": "^[MFAPR][0-9]+$"},
        "grade": {"enum": ["manual", "filing", "analyst", "press", "research"]},
        "citation": {"type": "string", "minLength": 1},
        "access_status": {"enum": ["direct", "bot-blocked"]},
        "registry_url": {"type": "string", "format": "uri"},
        "direct_url": {"type": "string", "format": "uri"}
      }
    }
  }
}
