{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.michaeldariuseastwood.com/schemas/citation-authority-policy.schema.json",
  "title": "Citation authority policy",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "policyId", "dateModified", "programme", "paperDoiKeys", "paperRelations", "software", "datasets", "outputs"],
  "properties": {
    "schemaVersion": {"const": 1},
    "policyId": {"type": "string", "minLength": 1},
    "dateModified": {"type": "string", "format": "date"},
    "programme": {"$ref": "#/$defs/resource"},
    "paperDoiKeys": {
      "type": "object",
      "propertyNames": {"pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"},
      "additionalProperties": {"type": "string", "minLength": 1}
    },
    "paperRelations": {
      "type": "object",
      "propertyNames": {"pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"},
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "required": ["relationType", "targetSlug", "reason"],
        "properties": {
          "relationType": {"enum": ["IsVersionOf", "IsNewVersionOf", "IsPreviousVersionOf", "IsSupplementTo", "References"]},
          "targetSlug": {"type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"},
          "reason": {"type": "string", "minLength": 1}
        }
      }
    },
    "software": {"$ref": "#/$defs/resource"},
    "datasets": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {"$ref": "#/$defs/resource"}
    },
    "outputs": {
      "type": "object",
      "additionalProperties": false,
      "required": ["authority", "csl", "bibtex", "ris", "cff"],
      "properties": {
        "authority": {"type": "string", "minLength": 1},
        "csl": {"type": "string", "minLength": 1},
        "bibtex": {"type": "string", "minLength": 1},
        "ris": {"type": "string", "minLength": 1},
        "cff": {"type": "string", "minLength": 1}
      }
    }
  },
  "$defs": {
    "resource": {
      "type": "object",
      "additionalProperties": false,
      "required": ["resourceId", "citationKey", "resourceType"],
      "properties": {
        "resourceId": {"type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"},
        "citationKey": {"type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"},
        "resourceType": {"enum": ["programme", "paper", "book", "dataset", "software", "report"]},
        "doiKey": {"type": "string", "minLength": 1},
        "title": {"type": "string", "minLength": 1},
        "url": {"type": "string", "format": "uri"},
        "repositoryCode": {"type": "string", "format": "uri"},
        "datePublished": {"type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"},
        "dateModified": {"type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"}
      }
    }
  }
}
