{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hieropedia.org/schemas/citation-metadata-1.1.schema.json",
  "type": "object",
  "required": [
    "schemaVersion",
    "articleId",
    "locale",
    "canonicalUrl",
    "title",
    "articleVersion",
    "translationVersion",
    "translationState",
    "publishedOnOrBefore",
    "lastReviewed",
    "retrievedOn",
    "authorship",
    "formattedCitation",
    "cslJson",
    "bibtex",
    "claimMapUrl",
    "claims"
  ],
  "properties": {
    "schemaVersion": {
      "const": "1.1"
    },
    "articleId": {
      "type": "string",
      "pattern": "^hp:"
    },
    "locale": {
      "type": "string"
    },
    "canonicalUrl": {
      "type": "string",
      "format": "uri"
    },
    "title": {
      "type": "string"
    },
    "articleVersion": {
      "type": "string"
    },
    "translationVersion": {
      "type": "string"
    },
    "translationState": {
      "enum": [
        "source",
        "current",
        "stale",
        "review-needed",
        "missing"
      ]
    },
    "translationRevisedOn": {
      "type": [
        "string",
        "null"
      ],
      "format": "date"
    },
    "translationMethod": {
      "type": "string"
    },
    "translationCompleteness": {
      "type": "string"
    },
    "lastRevised": {
      "type": "string",
      "format": "date"
    },
    "lastReviewed": {
      "type": "string",
      "format": "date"
    },
    "retrievedOn": {
      "type": "string",
      "format": "date"
    },
    "authorship": {
      "const": "Hieropedia Editorial"
    },
    "formattedCitation": {
      "type": "string"
    },
    "cslJson": {
      "type": "object"
    },
    "bibtex": {
      "type": "string"
    },
    "citationKey": {
      "type": "string"
    },
    "claimMapUrl": {
      "type": "string",
      "format": "uri"
    },
    "evidenceDossier": {
      "anyOf": [
        {
          "type": "object"
        },
        {
          "type": "null"
        }
      ]
    },
    "preservationManifest": {
      "anyOf": [
        {
          "type": "string",
          "format": "uri"
        },
        {
          "type": "null"
        }
      ]
    },
    "claims": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/claim"
      }
    },
    "publishedOnOrBefore": {
      "type": [
        "string",
        "null"
      ],
      "format": "date"
    }
  },
  "additionalProperties": false,
  "$defs": {
    "claim": {
      "type": "object",
      "required": [
        "claimId",
        "segmentId",
        "anchor",
        "sourceHash",
        "translationHash",
        "sourcePointers"
      ],
      "properties": {
        "claimId": {
          "type": "string",
          "pattern": "^hp:"
        },
        "segmentId": {
          "type": "string",
          "pattern": "^s[0-9]{3}$"
        },
        "anchor": {
          "type": "string",
          "pattern": "^claim-"
        },
        "sourceHash": {
          "type": "string"
        },
        "translationHash": {
          "type": "string"
        },
        "excerpt": {
          "type": "string"
        },
        "sourcePointers": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "kind",
              "target"
            ],
            "properties": {
              "kind": {
                "type": "string"
              },
              "target": {
                "type": "string",
                "format": "uri",
                "pattern": "^[Hh][Tt][Tt][Pp][Ss]?://"
              }
            },
            "additionalProperties": false,
            "allOf": [
              {
                "if": {
                  "properties": {
                    "kind": {
                      "enum": [
                        "editorial-record",
                        "evidence-dossier"
                      ]
                    }
                  },
                  "required": [
                    "kind"
                  ]
                },
                "then": {
                  "properties": {
                    "target": {
                      "pattern": "^https://hieropedia\\.org/"
                    }
                  }
                }
              }
            ]
          }
        },
        "sourceReferences": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/sourceReference"
          }
        }
      },
      "additionalProperties": false
    },
    "sourceReference": {
      "type": "object",
      "required": [
        "referenceId",
        "referenceUrl",
        "sourceUrls"
      ],
      "properties": {
        "referenceId": {
          "type": "string",
          "minLength": 1
        },
        "referenceUrl": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://hieropedia\\.org/[^?#]+#[^\\s]+$"
        },
        "sourceUrls": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "format": "uri",
            "pattern": "^[Hh][Tt][Tt][Pp][Ss]?://(?:[^/?#@]*@)?(?:\\[[^\\]\\s]+\\]|[^/?#:@\\[\\]\\s]+)(?::[0-9]*)?(?:[/?#]|$)"
          }
        }
      },
      "additionalProperties": false
    },
    "claimMap": {
      "type": "object",
      "required": [
        "schemaVersion",
        "articleId",
        "locale",
        "canonicalUrl",
        "claims"
      ],
      "properties": {
        "schemaVersion": {
          "const": "1.1"
        },
        "articleId": {
          "type": "string",
          "pattern": "^hp:"
        },
        "locale": {
          "type": "string"
        },
        "canonicalUrl": {
          "type": "string",
          "format": "uri"
        },
        "claims": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/claim"
          }
        }
      },
      "additionalProperties": false
    },
    "aggregate": {
      "type": "object",
      "required": [
        "schemaVersion",
        "generated",
        "articles"
      ],
      "properties": {
        "schemaVersion": {
          "const": "1.1"
        },
        "generated": {
          "type": "string",
          "format": "date"
        },
        "articles": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#"
          }
        }
      },
      "additionalProperties": false
    }
  }
}
