{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "source.schema.json",
  "title": "Manuscript source record",
  "description": "One manuscript. Every factual field carries a source URL; text fields also carry a licence.",
  "type": "object",
  "required": [
    "slug",
    "title",
    "holding",
    "date",
    "iiif",
    "links"
  ],
  "properties": {
    "slug": {
      "type": "string",
      "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
    },
    "siglum": {
      "type": [
        "string",
        "null"
      ]
    },
    "siglumSource": {
      "type": [
        "string",
        "null"
      ]
    },
    "title": {
      "type": "string",
      "minLength": 1
    },
    "altTitles": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "holding": {
      "type": "object",
      "required": [
        "library",
        "city",
        "country",
        "shelfmark"
      ],
      "properties": {
        "library": {
          "type": "string",
          "minLength": 1
        },
        "libraryWikidata": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^(Q[0-9]+)?$"
        },
        "city": {
          "type": "string"
        },
        "country": {
          "type": "string",
          "pattern": "^[A-Z]{2}$"
        },
        "shelfmark": {
          "type": "string",
          "description": "Empty when no shelfmark is recorded; the title is then shown in its place."
        },
        "lat": {
          "type": [
            "number",
            "null"
          ],
          "minimum": -90,
          "maximum": 90
        },
        "lon": {
          "type": [
            "number",
            "null"
          ],
          "minimum": -180,
          "maximum": 180
        },
        "source": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "date": {
      "type": "object",
      "required": [
        "label"
      ],
      "properties": {
        "label": {
          "type": "string"
        },
        "notBefore": {
          "type": [
            "integer",
            "null"
          ]
        },
        "notAfter": {
          "type": [
            "integer",
            "null"
          ]
        },
        "source": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "origin": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "label": {
          "type": "string"
        },
        "source": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "repertoire": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "term"
        ],
        "properties": {
          "term": {
            "type": "string"
          },
          "source": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    },
    "extent": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "folios": {
          "type": [
            "integer",
            "null"
          ]
        },
        "label": {
          "type": [
            "string",
            "null"
          ]
        },
        "source": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "condition": {
      "description": "Physical state, only as the cited record words it; quote = its exact words.",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "value",
        "quote",
        "source"
      ],
      "properties": {
        "value": {
          "enum": [
            null,
            "complete",
            "fragment",
            "fragments",
            "palimpsest",
            "lost"
          ]
        },
        "quote": {
          "type": "string"
        },
        "source": {
          "type": "string",
          "pattern": "^(https://.+)?$"
        }
      }
    },
    "format": {
      "description": "Physical form or layout, only as the cited record words it; quote = its exact words.",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "value",
        "quote",
        "source"
      ],
      "properties": {
        "value": {
          "enum": [
            null,
            "codex",
            "choirbook",
            "parts",
            "roll",
            "single leaf"
          ]
        },
        "quote": {
          "type": "string"
        },
        "source": {
          "type": "string",
          "pattern": "^(https://.+)?$"
        }
      }
    },
    "notation": {
      "description": "Notations the cited record or article names; quote = its exact words.",
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "term",
          "quote",
          "source"
        ],
        "properties": {
          "term": {
            "type": "string",
            "minLength": 1
          },
          "quote": {
            "type": "string",
            "minLength": 1
          },
          "source": {
            "type": "string",
            "pattern": "^https://.+$"
          }
        }
      }
    },
    "iiif": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "manifest",
          "provider",
          "licenceClass"
        ],
        "properties": {
          "manifest": {
            "type": "string",
            "pattern": "^(https://|site:)"
          },
          "presentation": {
            "enum": [
              2,
              3
            ]
          },
          "provider": {
            "type": "string"
          },
          "requiredStatement": {
            "type": [
              "string",
              "null"
            ]
          },
          "rights": {
            "type": [
              "string",
              "null"
            ]
          },
          "licenceClass": {
            "enum": [
              "open",
              "noncommercial",
              "unstated"
            ]
          },
          "canvases": {
            "type": [
              "integer",
              "null"
            ]
          },
          "corsManifest": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "corsImageInfo": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "checked": {
            "type": [
              "string",
              "null"
            ]
          },
          "thumbnail": {
            "oneOf": [
              {
                "type": [
                  "string",
                  "null"
                ]
              },
              {
                "type": "object",
                "required": [
                  "request"
                ],
                "properties": {
                  "request": {
                    "type": "string",
                    "pattern": "^https://"
                  },
                  "width": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "height": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  }
                }
              }
            ]
          },
          "startCanvas": {
            "type": [
              "string",
              "null"
            ]
          },
          "viewer": {
            "type": [
              "string",
              "null"
            ]
          },
          "label": {
            "type": [
              "string",
              "null"
            ]
          },
          "logo": {
            "type": [
              "string",
              "null"
            ]
          },
          "imageApi": {
            "enum": [
              2,
              3,
              null
            ]
          },
          "imageService": {
            "type": [
              "string",
              "null"
            ]
          },
          "viewerReady": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "folioMap": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      }
    },
    "links": {
      "type": "object",
      "properties": {
        "wikidata": {
          "type": [
            "string",
            "null"
          ]
        },
        "wikipedia": {
          "type": [
            "string",
            "null"
          ]
        },
        "diamm": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^(https://www\\.diamm\\.ac\\.uk/sources/[0-9]+/)?$"
        },
        "rism": {
          "type": [
            "string",
            "null"
          ]
        },
        "catalogue": {
          "type": [
            "string",
            "null"
          ]
        },
        "libraryViewer": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "summary": {
      "type": [
        "object",
        "null"
      ],
      "required": [
        "text",
        "source",
        "licence"
      ],
      "properties": {
        "text": {
          "type": "string"
        },
        "source": {
          "type": "string"
        },
        "licence": {
          "type": "string"
        },
        "licenceUrl": {
          "type": [
            "string",
            "null"
          ]
        },
        "attribution": {
          "type": [
            "string",
            "null"
          ]
        },
        "lang": {
          "type": [
            "string",
            "null"
          ]
        },
        "sic": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "description": "Words in the quoted text that are reproduced as the source spells them; the site marks the first occurrence of each with [sic]. The quote itself is never edited."
        }
      }
    },
    "contents": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "title",
          "source"
        ],
        "properties": {
          "folio": {
            "type": [
              "string",
              "null"
            ]
          },
          "title": {
            "type": "string"
          },
          "incipit": {
            "type": [
              "string",
              "null"
            ]
          },
          "composer": {
            "type": [
              "string",
              "null"
            ]
          },
          "composerWikidata": {
            "type": [
              "string",
              "null"
            ]
          },
          "voices": {
            "type": [
              "integer",
              "null"
            ]
          },
          "genre": {
            "type": [
              "string",
              "null"
            ]
          },
          "work": {
            "type": [
              "string",
              "null"
            ]
          },
          "source": {
            "type": "string"
          },
          "licence": {
            "type": [
              "string",
              "null"
            ]
          },
          "canvas": {
            "type": [
              "string",
              "null"
            ]
          },
          "folioRange": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    },
    "featured": {
      "type": "boolean"
    },
    "added": {
      "type": [
        "string",
        "null"
      ]
    },
    "fixture": {
      "type": "boolean"
    },
    "viewerReady": {
      "type": [
        "boolean",
        "null"
      ]
    },
    "notes": {
      "type": [
        "string",
        "null"
      ]
    }
  }
}
