{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Knowledge entity v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "kind",
    "title",
    "jurisdiction",
    "language",
    "version",
    "publication",
    "evidence",
    "implementation",
    "effective",
    "citations",
    "rights",
    "content",
    "relationships",
    "history"
  ],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^[A-Za-z0-9][A-Za-z0-9:._-]+$"
    },
    "kind": {
      "enum": [
        "source",
        "claim",
        "document-type",
        "reporting-form",
        "field",
        "explainer",
        "review",
        "form-version",
        "artifact",
        "release",
        "change"
      ]
    },
    "title": {
      "type": "string",
      "minLength": 1
    },
    "jurisdiction": {
      "type": "string"
    },
    "language": {
      "type": "string"
    },
    "version": {
      "type": "string"
    },
    "publication": {
      "enum": [
        "draft",
        "published",
        "archived"
      ]
    },
    "evidence": {
      "enum": [
        "unverified",
        "source-checked",
        "expert-reviewed",
        "disputed"
      ]
    },
    "implementation": {
      "enum": [
        "not-assessed",
        "proposed",
        "implemented",
        "tested"
      ]
    },
    "effective": {
      "type": "object",
      "required": [
        "from",
        "to",
        "checkedAt"
      ],
      "additionalProperties": false,
      "properties": {
        "from": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
        },
        "to": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
        },
        "checkedAt": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
        }
      }
    },
    "claimClass": {
      "enum": [
        "law",
        "common-practice",
        "contract-policy",
        "organization-policy",
        "recommendation",
        "official-instruction"
      ]
    },
    "applicability": {
      "type": "string"
    },
    "uncertainty": {
      "type": "string"
    },
    "citations": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "sourceId",
          "url",
          "locator",
          "checkedAt"
        ],
        "additionalProperties": false,
        "properties": {
          "sourceId": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "pattern": "^https://"
          },
          "locator": {
            "type": "string"
          },
          "checkedAt": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    },
    "rights": {
      "type": "object",
      "required": [
        "status",
        "note"
      ],
      "additionalProperties": false,
      "properties": {
        "status": {
          "enum": [
            "unknown",
            "original",
            "public-domain",
            "permission",
            "restricted"
          ]
        },
        "note": {
          "type": "string"
        }
      }
    },
    "content": {
      "type": "object",
      "properties": {
        "humanReviews": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "outcome",
              "reviewer",
              "reviewedAt",
              "scope",
              "reviewedRevision"
            ],
            "properties": {
              "outcome": {
                "enum": [
                  "reviewed",
                  "changes-requested"
                ]
              },
              "reviewer": {
                "type": [
                  "string",
                  "null"
                ],
                "minLength": 1
              },
              "reviewedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}(T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]+)?Z)?$"
              },
              "scope": {
                "type": [
                  "string",
                  "null"
                ],
                "minLength": 1
              },
              "reviewedRevision": {
                "type": [
                  "string",
                  "null"
                ],
                "minLength": 1
              },
              "reviewedContentHash": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^[a-f0-9]{64}$"
              }
            }
          }
        }
      }
    },
    "relationships": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "targetId",
          "relation",
          "maturity"
        ],
        "additionalProperties": false,
        "properties": {
          "targetId": {
            "type": "string"
          },
          "relation": {
            "type": "string"
          },
          "maturity": {
            "enum": [
              "proposed",
              "implemented",
              "tested",
              "reference"
            ]
          }
        }
      }
    },
    "history": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "at",
          "actor",
          "note"
        ],
        "additionalProperties": false,
        "properties": {
          "at": {
            "type": "string"
          },
          "actor": {
            "type": "string"
          },
          "note": {
            "type": "string"
          }
        }
      }
    },
    "provenance": {
      "type": "object"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "kind": {
            "const": "claim"
          }
        },
        "required": [
          "kind"
        ]
      },
      "then": {
        "required": [
          "claimClass",
          "applicability",
          "uncertainty"
        ]
      }
    }
  ]
}
