{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:tandem:schema:chapter",
  "title": "Tandem chapter manifest",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "title",
    "content_type",
    "content_sha256",
    "uris"
  ],
  "properties": {
    "schema": {
      "const": "urn:tandem:chapter"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120,
      "pattern": "^[^\\u0000-\\u001f\\u007f]+$"
    },
    "content_type": {
      "type": "string",
      "minLength": 3,
      "maxLength": 127,
      "pattern": "^[a-z0-9][a-z0-9!#$&^_.+-]{0,63}/[a-z0-9][a-z0-9!#$&^_.+-]{0,62}$"
    },
    "content_sha256": {
      "$ref": "#/$defs/sha256"
    },
    "uris": {
      "type": "array",
      "maxItems": 8,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "minLength": 10,
        "maxLength": 2048,
        "pattern": "^(ipfs://[A-Za-z0-9]+(?:/[^\\s]*)?|ar://[A-Za-z0-9_-]+|sha256://[0-9a-f]{64})$"
      }
    },
    "encryption": {
      "oneOf": [
        {
          "$ref": "#/$defs/xchacha20"
        }
      ]
    },
    "display": {
      "$ref": "#/$defs/display"
    }
  },
  "$defs": {
    "sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "base64": {
      "type": "string",
      "pattern": "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"
    },
    "xchacha20": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "scheme",
        "nonce_base64",
        "key_commitment_sha256"
      ],
      "properties": {
        "scheme": {
          "const": "xchacha20-poly1305"
        },
        "nonce_base64": {
          "allOf": [
            {
              "$ref": "#/$defs/base64"
            },
            {
              "minLength": 32,
              "maxLength": 32
            }
          ]
        },
        "key_commitment_sha256": {
          "$ref": "#/$defs/sha256"
        }
      }
    },
    "display": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "fit": {
          "enum": [
            "contain",
            "cover",
            "native"
          ]
        },
        "background": {
          "type": "string",
          "pattern": "^#[0-9a-fA-F]{6}$"
        },
        "alt": {
          "type": "string",
          "maxLength": 500,
          "pattern": "^[^\\u0000-\\u0008\\u000b\\u000c\\u000e-\\u001f\\u007f]*$"
        }
      }
    }
  }
}
