{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aiobservatory.in/data/evidence-pilot.schema.json",
  "title": "IAIRO project-evidence pilot",
  "type": "object",
  "additionalProperties": false,
  "required": ["contractVersion", "metadata", "layers", "projects", "entities", "sources", "relationships"],
  "properties": {
    "contractVersion": { "const": "0.1.0" },
    "metadata": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "title", "status", "statusLabel", "snapshotDate", "recordPolicy", "reviewPolicy", "interpretation"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "title": { "type": "string", "minLength": 1 },
        "status": { "enum": ["pilot_provisional", "release_candidate", "released"] },
        "statusLabel": { "type": "string", "minLength": 1 },
        "snapshotDate": { "type": "string", "format": "date" },
        "recordPolicy": { "type": "string", "minLength": 1 },
        "reviewPolicy": { "const": "double_independent" },
        "interpretation": { "type": "string", "minLength": 1 }
      }
    },
    "layers": {
      "type": "array",
      "minItems": 9,
      "maxItems": 9,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["key", "label"],
        "properties": {
          "key": { "enum": ["funding", "researcher", "institution", "publication", "dataset_model", "compute_infrastructure", "industry_startup", "deployment", "outcome"] },
          "label": { "type": "string", "minLength": 1 }
        }
      }
    },
    "projects": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "name", "summary", "leadInstitutionId", "funderIds", "period", "sector"],
        "properties": {
          "id": { "type": "string", "pattern": "^project:" },
          "name": { "type": "string", "minLength": 1 },
          "summary": { "type": "string", "minLength": 1 },
          "leadInstitutionId": { "type": "string", "minLength": 1 },
          "funderIds": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
          "period": {
            "type": "object",
            "additionalProperties": false,
            "required": ["start", "end"],
            "properties": {
              "start": { "type": ["string", "null"] },
              "end": { "type": ["string", "null"] }
            }
          },
          "sector": { "type": "string", "minLength": 1 }
        }
      }
    },
    "entities": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "type", "name", "identifiers", "resolution"],
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "type": { "enum": ["funding_grant", "researcher", "institution", "publication", "dataset", "model", "compute_infrastructure", "industry_startup", "deployment", "outcome"] },
          "name": { "type": "string", "minLength": 1 },
          "identifiers": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": ["scheme", "value"],
              "properties": {
                "scheme": { "type": "string" },
                "value": { "type": "string" },
                "url": { "type": "string", "format": "uri" }
              }
            }
          },
          "resolution": {
            "type": "object",
            "additionalProperties": false,
            "required": ["status", "method", "confidenceBand"],
            "properties": {
              "status": { "enum": ["resolved", "described", "needs_reconciliation"] },
              "method": { "type": "string", "minLength": 1 },
              "confidenceBand": { "enum": ["high", "medium", "low"] }
            }
          }
        }
      }
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "title", "publisher", "url", "publishedDate", "accessedDate", "sourceType"],
        "properties": {
          "id": { "type": "string", "pattern": "^source:" },
          "title": { "type": "string", "minLength": 1 },
          "publisher": { "type": "string", "minLength": 1 },
          "url": { "type": "string", "format": "uri", "pattern": "^https://" },
          "publishedDate": { "type": ["string", "null"], "format": "date" },
          "accessedDate": { "type": "string", "format": "date" },
          "sourceType": { "type": "string", "minLength": 1 }
        }
      }
    },
    "relationships": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "projectId", "layer", "type", "sourceEntityId", "targetEntityId", "evidenceSummary", "sourceRef", "observedDate", "lastChecked", "confidence", "validation"],
        "properties": {
          "id": { "type": "string", "pattern": "^relation:" },
          "projectId": { "type": "string", "pattern": "^project:" },
          "layer": { "enum": ["funding", "researcher", "institution", "publication", "dataset_model", "compute_infrastructure", "industry_startup", "deployment", "outcome"] },
          "type": {
            "enum": [
              "programme_supports_project",
              "grant_supports_project",
              "institution_participates_in_project",
              "institution_operates_project",
              "institution_develops_project",
              "organisation_supports_project",
              "researcher_leads_project",
              "project_uses_model_or_dataset",
              "project_uses_model",
              "project_releases_dataset",
              "project_releases_model",
              "project_uses_infrastructure",
              "project_operates_deployment",
              "deployment_reports_outcome",
              "deployment_reports_usage",
              "deployment_reports_adoption"
            ]
          },
          "sourceEntityId": { "type": "string", "minLength": 1 },
          "targetEntityId": { "type": "string", "minLength": 1 },
          "evidenceSummary": { "type": "string", "minLength": 1 },
          "sourceRef": { "type": "string", "pattern": "^source:" },
          "observedDate": { "type": "string", "format": "date" },
          "lastChecked": { "type": "string", "format": "date" },
          "confidence": {
            "type": "object",
            "additionalProperties": false,
            "required": ["level", "rationale"],
            "properties": {
              "level": { "enum": ["high", "medium", "low", "unscored"] },
              "rationale": { "type": "string", "minLength": 1 }
            }
          },
          "validation": {
            "type": "object",
            "additionalProperties": false,
            "required": ["status", "reviewCount", "adjudicated"],
            "properties": {
              "status": { "enum": ["source_supported", "needs_review", "human_reviewed", "disputed", "rejected", "superseded"] },
              "reviewCount": { "type": "integer", "minimum": 0 },
              "adjudicated": { "type": "boolean" }
            }
          }
        }
      }
    }
  }
}
