{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://opensheaf.org/schemas/opensheaf-collection-0.1.schema.json",
  "title": "OpenSheaf member list (members.json), format opensheaf-collection/0.1",
  "$comment": "Part of OpenSheaf 0.1 (https://opensheaf.org). Dedicated to the public domain under CC0 1.0: https://creativecommons.org/publicdomain/zero/1.0/",
  "type": "object",
  "required": [
    "format",
    "type",
    "members"
  ],
  "properties": {
    "format": {
      "const": "opensheaf-collection/0.1"
    },
    "order": {
      "enum": [
        "manual",
        "issued-desc",
        "issued-asc"
      ]
    },
    "members": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "kind",
          "archive",
          "archiveUrl",
          "id"
        ],
        "properties": {
          "kind": {
            "enum": [
              "document",
              "collection"
            ]
          },
          "archive": {
            "type": "string",
            "format": "uri"
          },
          "archiveUrl": {
            "type": "string",
            "format": "uri",
            "pattern": "/$"
          },
          "id": {
            "type": "string",
            "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
            "maxLength": 64
          },
          "version": {
            "type": "string",
            "pattern": "^v[1-9][0-9]*$"
          },
          "inventorySha512": {
            "type": "string",
            "pattern": "^[0-9a-f]{128}$"
          },
          "mirrors": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri",
              "pattern": "/$"
            }
          },
          "doi": {
            "type": "string"
          },
          "conceptDoi": {
            "type": "string"
          },
          "follow": {
            "const": "latest"
          },
          "cite": {
            "type": "object",
            "properties": {
              "title": {
                "type": "string"
              },
              "creators": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "year": {
                "type": "integer"
              },
              "issued": {
                "type": "string"
              }
            }
          },
          "revisions": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "required": [
                "documentVersion",
                "version",
                "inventorySha512"
              ],
              "properties": {
                "documentVersion": {
                  "type": "integer",
                  "minimum": 1
                },
                "version": {
                  "type": "string",
                  "pattern": "^v[1-9][0-9]*$"
                },
                "inventorySha512": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{128}$"
                }
              }
            }
          }
        }
      }
    },
    "type": {
      "enum": [
        "archive",
        "selection"
      ],
      "description": "archive: members pin objects whole (version, inventorySha512, optional follow); selection: members pin revision sets (revisions)"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "type": {
            "const": "archive"
          }
        }
      },
      "then": {
        "properties": {
          "members": {
            "items": {
              "required": [
                "version",
                "inventorySha512"
              ],
              "not": {
                "required": [
                  "revisions"
                ]
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "selection"
          }
        }
      },
      "then": {
        "properties": {
          "members": {
            "items": {
              "required": [
                "revisions"
              ],
              "not": {
                "anyOf": [
                  {
                    "required": [
                      "version"
                    ]
                  },
                  {
                    "required": [
                      "inventorySha512"
                    ]
                  },
                  {
                    "required": [
                      "follow"
                    ]
                  }
                ]
              }
            }
          }
        }
      }
    }
  ]
}
