{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://botlandscape.com/landscape.schema.json",
  "title": "Bot Landscape machine-readable export",
  "type": "object",
  "additionalProperties": false,
  "required": ["$schema", "schema_version", "site", "counts", "statistics", "pages", "sources", "entities", "claims"],
  "properties": {
    "$schema": {"const": "https://botlandscape.com/landscape.schema.json"},
    "schema_version": {"const": 3},
    "site": {"type": "string", "format": "uri"},
    "counts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["pages", "tables", "rows", "sources", "entities", "claims"],
      "properties": {
        "pages": {"type": "integer", "minimum": 0},
        "tables": {"type": "integer", "minimum": 0},
        "rows": {"type": "integer", "minimum": 0},
        "sources": {"type": "integer", "minimum": 0},
        "entities": {"type": "integer", "minimum": 0},
        "claims": {"type": "integer", "minimum": 0}
      }
    },
    "statistics": {
      "type": "object",
      "additionalProperties": {"type": "integer", "minimum": 0}
    },
    "pages": {"type": "array", "items": {"$ref": "#/$defs/page"}},
    "sources": {"type": "array", "items": {"$ref": "#/$defs/source"}},
    "entities": {"type": "array", "items": {"$ref": "#/$defs/entity"}},
    "claims": {"type": "array", "items": {"$ref": "#/$defs/claim"}}
  },
  "$defs": {
    "link": {
      "type": "object",
      "additionalProperties": false,
      "required": ["text", "url"],
      "properties": {
        "text": {"type": "string"},
        "url": {"type": "string", "format": "uri"}
      }
    },
    "cell": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "scope", "column", "colspan", "rowspan", "text", "evidence", "links"],
      "properties": {
        "kind": {"enum": ["header", "value"]},
        "scope": {"type": ["string", "null"]},
        "column": {"type": "integer", "minimum": 0},
        "colspan": {"type": "integer", "minimum": 1},
        "rowspan": {"type": "integer", "minimum": 1},
        "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", "kind", "cells"],
      "properties": {
        "id": {"type": ["string", "null"]},
        "kind": {"enum": ["header", "group", "data"]},
        "cells": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/cell"}}
      }
    },
    "table": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "class", "caption", "source_urls", "rows"],
      "properties": {
        "id": {"type": "string", "minLength": 1},
        "class": {"type": "string", "minLength": 1},
        "caption": {"type": "string", "minLength": 1},
        "source_urls": {"type": "array", "uniqueItems": true, "items": {"type": "string", "format": "uri"}},
        "rows": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/row"}}
      }
    },
    "section": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "heading", "tables"],
      "properties": {
        "id": {"type": "string", "minLength": 1},
        "heading": {"type": "string", "minLength": 1},
        "tables": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/table"}}
      }
    },
    "page": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "url", "title", "description", "sections"],
      "properties": {
        "path": {"type": "string", "pattern": "\\.html$"},
        "url": {"type": "string", "format": "uri"},
        "title": {"type": "string", "minLength": 1},
        "description": {"type": "string", "minLength": 1},
        "sections": {"type": "array", "items": {"$ref": "#/$defs/section"}}
      }
    },
    "document": {
      "type": "object",
      "additionalProperties": false,
      "required": ["publisher", "title", "type", "publication_date", "version", "commit", "license", "label"],
      "properties": {
        "publisher": {"type": "string", "minLength": 1},
        "title": {"type": "string", "minLength": 1},
        "type": {"type": "string", "minLength": 1},
        "publication_date": {"type": ["string", "null"]},
        "version": {"type": ["string", "null"]},
        "commit": {"type": ["string", "null"]},
        "license": {"type": ["string", "null"]},
        "label": {"type": "string", "minLength": 1}
      }
    },
    "access": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "retrieved", "note"],
      "properties": {
        "status": {"enum": ["direct", "bot-blocked"]},
        "retrieved": {"type": "string", "format": "date"},
        "note": {"type": ["string", "null"]}
      }
    },
    "locator": {
      "type": "object",
      "additionalProperties": false,
      "required": ["registry_url", "direct_url", "fragment"],
      "properties": {
        "registry_url": {"type": "string", "format": "uri"},
        "direct_url": {"type": "string", "format": "uri"},
        "fragment": {"type": ["string", "null"]}
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "topic", "marker", "grade", "document", "access", "locator", "supports"],
      "properties": {
        "id": {"type": "string", "pattern": "^[a-z0-9-]+-[mfapr][0-9]+$"},
        "topic": {"type": "string", "minLength": 1},
        "marker": {"type": "string", "pattern": "^[MFAPR][0-9]+$"},
        "grade": {"enum": ["manual", "filing", "analyst", "press", "research"]},
        "document": {"$ref": "#/$defs/document"},
        "access": {"$ref": "#/$defs/access"},
        "locator": {"$ref": "#/$defs/locator"},
        "supports": {"type": "string", "minLength": 1}
      }
    },
    "entity": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "type", "name", "category", "category_label", "url", "catalogue_url", "model_status", "model_preview_url", "description", "evidence", "links"],
      "properties": {
        "id": {"type": "string", "pattern": "^catalogue--[a-z0-9-]+$"},
        "type": {"const": "catalogue-item"},
        "name": {"type": "string", "minLength": 1},
        "category": {"type": "string", "minLength": 1},
        "category_label": {"type": "string", "minLength": 1},
        "url": {"type": "string", "format": "uri"},
        "catalogue_url": {"type": "string", "format": "uri"},
        "model_status": {"type": "string", "minLength": 1},
        "model_preview_url": {"type": ["string", "null"], "format": "uri"},
        "description": {"type": "string", "minLength": 1},
        "evidence": {"type": "array", "uniqueItems": true, "items": {"type": "string"}},
        "links": {"type": "array", "items": {"$ref": "#/$defs/link"}}
      }
    },
    "claim-value": {
      "type": "object",
      "additionalProperties": false,
      "required": ["state", "text"],
      "properties": {
        "state": {"enum": ["reported", "missing"]},
        "text": {"type": "string"}
      }
    },
    "claim": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "url", "page_path", "section_id", "table_id", "class", "row_id", "metric", "column", "subjects", "value", "evidence", "links"],
      "properties": {
        "id": {"type": "string", "minLength": 1},
        "url": {"type": "string", "format": "uri"},
        "page_path": {"type": "string", "pattern": "\\.html$"},
        "section_id": {"type": "string", "minLength": 1},
        "table_id": {"type": "string", "minLength": 1},
        "class": {"type": "string", "minLength": 1},
        "row_id": {"type": "string", "minLength": 1},
        "metric": {"type": "string", "minLength": 1},
        "column": {"type": "integer", "minimum": 0},
        "subjects": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"type": "string", "minLength": 1}},
        "value": {"$ref": "#/$defs/claim-value"},
        "evidence": {"type": "array", "uniqueItems": true, "items": {"type": "string"}},
        "links": {"type": "array", "items": {"$ref": "#/$defs/link"}}
      }
    }
  }
}
