{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "midnight-nft-item/1",
  "title": "NFT metadata for Midnight: item file",
  "type": "object",
  "required": ["schema", "name", "image", "image_sha256"],
  "properties": {
    "schema": { "const": "midnight-nft-item/1" },
    "name": { "type": "string", "minLength": 1, "maxLength": 64, "description": "At most 64 bytes of UTF-8 (maxLength here counts characters; the validator counts bytes)." },
    "title": { "type": "string", "minLength": 1, "maxLength": 48, "pattern": "^\\S(.*\\S)?$", "description": "The name the item has of its own, apart from its number. At most 48 bytes, and name must contain it (the validator checks both). Sealed with the picture." },
    "description": { "type": "string" },
    "image": { "$ref": "#/$defs/uri" },
    "image_sha256": { "$ref": "#/$defs/sha256" },
    "mediaType": { "type": "string", "pattern": "^[a-z]+/[a-z0-9.+-]+$" },
    "external_url": { "$ref": "#/$defs/uri" },
    "animation_url": { "$ref": "#/$defs/uri" },
    "animation_sha256": { "$ref": "#/$defs/sha256" },
    "attributes": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["trait_type", "value"],
        "properties": {
          "trait_type": { "type": "string", "minLength": 1 },
          "value": { "type": ["string", "number", "boolean"] },
          "display_type": { "enum": ["number", "boost_number", "boost_percentage", "date"] },
          "max_value": { "type": "number" }
        },
        "if": { "required": ["display_type"] },
        "then": { "properties": { "value": { "type": "number" } } }
      }
    },
    "files": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "src", "sha256"],
        "properties": { "name": { "type": "string" }, "mediaType": { "type": "string" }, "src": { "$ref": "#/$defs/uri" }, "sha256": { "$ref": "#/$defs/sha256" } }
      }
    },
    "rarity": {
      "type": "object",
      "required": ["rank", "of", "method"],
      "properties": { "rank": { "type": "integer", "minimum": 1 }, "of": { "type": "integer", "minimum": 1 }, "score": { "type": "number" }, "tier": { "type": "string" }, "method": { "type": "string" } }
    },
    "midnight": {
      "type": "object",
      "required": ["kind"],
      "properties": { "domainSep": { "$ref": "#/$defs/sha256" }, "kind": { "enum": ["unshielded", "shielded", "contract"] } },
      "if": { "properties": { "kind": { "enum": ["unshielded", "shielded"] } } },
      "then": { "required": ["domainSep"] }
    },
    "collection": { "type": "object", "properties": { "name": { "type": "string" }, "symbol": { "type": "string" } } }
  },
  "dependentRequired": { "animation_url": ["animation_sha256"] },
  "additionalProperties": true,
  "$comment": "Rules a schema cannot express and the validator checks: a trait_type appears once per item; a trait an item lacks is left out (no \"None\"); rarity is never a trait; string values have no spaces at their ends.",
  "$defs": {
    "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
    "uri": { "type": "string", "pattern": "^(ipfs|ar|https)://\\S+$" }
  }
}
