{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tune.toys/schemas/platform/media-version.schema.json",
  "title": "SoundVersion",
  "description": "One immutable upload of a media item: bytes, digest, rights, what the probe found and the tags the file carried. Never edited after creation; releases pin versions.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "id": {
      "$ref": "common.schema.json#/$defs/EntityId"
    },
    "mediaId": {
      "$ref": "common.schema.json#/$defs/EntityId"
    },
    "sha256": {
      "$ref": "common.schema.json#/$defs/Sha256Hex"
    },
    "sizeBytes": {
      "$ref": "common.schema.json#/$defs/ByteSize"
    },
    "mediaType": {
      "type": "string",
      "minLength": 3,
      "maxLength": 128,
      "pattern": "^[a-z]+/[A-Za-z0-9!#$&^_.+-]+$",
      "description": "Admitted media type without parameters."
    },
    "filename": {
      "type": "string",
      "minLength": 1,
      "maxLength": 255
    },
    "license": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "attribution": {
      "type": "string",
      "minLength": 0,
      "maxLength": 1024
    },
    "reusable": {
      "type": "boolean"
    },
    "probe": {
      "anyOf": [
        {
          "$ref": "#/$defs/MediaProbe"
        },
        {
          "type": "null"
        }
      ]
    },
    "embedded": {
      "anyOf": [
        {
          "$ref": "#/$defs/EmbeddedMetadata"
        },
        {
          "type": "null"
        }
      ]
    },
    "ingestState": {
      "$ref": "enums.schema.json#/$defs/IngestState"
    },
    "createdAt": {
      "$ref": "common.schema.json#/$defs/Timestamp"
    },
    "origin": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "provider": {
          "const": "tone3000"
        },
        "toneId": {
          "type": "string",
          "pattern": "^[0-9A-Za-z_-]{1,64}$"
        },
        "modelId": {
          "type": "string",
          "pattern": "^[0-9A-Za-z_-]{1,64}$"
        },
        "url": {
          "type": "string",
          "pattern": "^https://www[.]tone3000[.]com/[a-zA-Z0-9_./-]*$",
          "maxLength": 512
        }
      },
      "required": ["provider", "toneId", "modelId", "url"]
    }
  },
  "required": [
    "id",
    "mediaId",
    "sha256",
    "sizeBytes",
    "mediaType",
    "filename",
    "license",
    "attribution",
    "reusable",
    "probe",
    "embedded",
    "ingestState",
    "createdAt"
  ],
  "$defs": {
    "MediaProbe": {
      "title": "MediaProbe",
      "description": "Container facts read by the structural parser; keys apply per family.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "container": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        },
        "codec": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        },
        "sampleRate": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000
        },
        "bitDepth": {
          "type": "integer",
          "minimum": 1,
          "maximum": 64
        },
        "channels": {
          "type": "integer",
          "minimum": 1,
          "maximum": 64
        },
        "durationMs": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "bitRate": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "width": {
          "type": "integer",
          "minimum": 1,
          "maximum": 16384
        },
        "height": {
          "type": "integer",
          "minimum": 1,
          "maximum": 16384
        },
        "frameRate": {
          "type": "number",
          "minimum": 0,
          "maximum": 1000
        },
        "hasAudio": {
          "type": "boolean"
        },
        "tracks": {
          "type": "integer",
          "minimum": 0,
          "maximum": 65535
        },
        "ppq": {
          "type": "integer",
          "minimum": 1,
          "maximum": 32767
        },
        "events": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "noteCount": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "parts": {
          "type": "integer",
          "minimum": 0,
          "maximum": 4096
        },
        "measures": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        }
      }
    },
    "EmbeddedKey": {
      "title": "EmbeddedKey",
      "description": "Key carried by a tag or key signature; tags name only major or minor.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "root": {
          "type": "integer",
          "minimum": 0,
          "maximum": 11,
          "description": "Pitch class of the key root: 0 = C \u2026 11 = B."
        },
        "tonality": {
          "$ref": "enums.schema.json#/$defs/Tonality"
        },
        "mode": {
          "$ref": "enums.schema.json#/$defs/MusicalMode"
        }
      },
      "required": ["root"]
    },
    "EmbeddedMetadata": {
      "title": "EmbeddedMetadata",
      "description": "Tags parsed from the file (ID3, Vorbis, RIFF INFO, BWF, iXML, MP4 atoms, SMF meta events, MusicXML/MEI headers). Read once per version, never edited; declared values override them.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "title": {
          "type": "string",
          "minLength": 0,
          "maxLength": 128
        },
        "artist": {
          "type": "string",
          "minLength": 0,
          "maxLength": 128
        },
        "album": {
          "type": "string",
          "minLength": 0,
          "maxLength": 128
        },
        "composer": {
          "type": "string",
          "minLength": 0,
          "maxLength": 128
        },
        "lyricist": {
          "type": "string",
          "minLength": 0,
          "maxLength": 128
        },
        "year": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9999
        },
        "trackNumber": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9999
        },
        "genre": {
          "type": "string",
          "minLength": 0,
          "maxLength": 64,
          "description": "Raw genre text; not the closed vocabulary."
        },
        "bpm": {
          "type": "number",
          "minimum": 1,
          "maximum": 1000
        },
        "key": {
          "$ref": "#/$defs/EmbeddedKey"
        },
        "meter": {
          "$ref": "media-item.schema.json#/$defs/Meter"
        },
        "isrc": {
          "type": "string",
          "minLength": 12,
          "maxLength": 12
        },
        "iswc": {
          "type": "string",
          "minLength": 11,
          "maxLength": 15
        },
        "recordedAt": {
          "type": "string",
          "minLength": 0,
          "maxLength": 64,
          "description": "Raw date text as carried (BWF OriginationDate/Time, TDRC, DATE, encoding-date)."
        },
        "location": {
          "type": "string",
          "minLength": 0,
          "maxLength": 128
        },
        "originator": {
          "type": "string",
          "minLength": 0,
          "maxLength": 128
        },
        "device": {
          "type": "string",
          "minLength": 0,
          "maxLength": 128
        },
        "comment": {
          "type": "string",
          "minLength": 0,
          "maxLength": 1024
        },
        "picture": {
          "type": "boolean",
          "description": "A picture was present and extracted to an image version."
        },
        "instruments": {
          "type": "array",
          "maxItems": 32,
          "uniqueItems": true,
          "items": {
            "$ref": "media-vocabulary.schema.json#/$defs/Instrument"
          },
          "description": "From General MIDI programs or score-instrument parts."
        },
        "tempoChanges": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        },
        "lyrics": {
          "type": "boolean"
        }
      }
    }
  }
}
