{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tune.toys/schemas/platform/media-rendition.schema.json",
  "title": "SoundRendition",
  "description": "One derived artifact of a media version (peaks, preview, thumbnail, score page, piano roll, beats). Immutable; unique per version, kind, recipe, toolchain and profile.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "id": {
      "$ref": "common.schema.json#/$defs/EntityId"
    },
    "versionId": {
      "$ref": "common.schema.json#/$defs/EntityId"
    },
    "kind": {
      "$ref": "enums.schema.json#/$defs/RenditionKind"
    },
    "recipe": {
      "type": "string",
      "minLength": 1,
      "maxLength": 64,
      "description": "Named recipe the worker applied (for example `preview-30s`)."
    },
    "toolchain": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "description": "Tool and version that produced the bytes (for example `ffmpeg-7.1`)."
    },
    "profile": {
      "type": "string",
      "minLength": 0,
      "maxLength": 64,
      "description": "Variant within a kind (for example `512` for a thumbnail width); empty when there is one."
    },
    "sha256": {
      "anyOf": [
        {
          "$ref": "common.schema.json#/$defs/Sha256Hex"
        },
        {
          "type": "null"
        }
      ]
    },
    "sizeBytes": {
      "anyOf": [
        {
          "$ref": "common.schema.json#/$defs/ByteSize"
        },
        {
          "type": "null"
        }
      ]
    },
    "mediaType": {
      "anyOf": [
        {
          "type": "string",
          "minLength": 3,
          "maxLength": 128,
          "pattern": "^[a-z]+/[A-Za-z0-9!#$&^_.+-]+$",
          "description": "Admitted media type without parameters."
        },
        {
          "type": "null"
        }
      ]
    },
    "meta": {
      "$ref": "#/$defs/RenditionMeta"
    },
    "state": {
      "$ref": "enums.schema.json#/$defs/RenditionState"
    },
    "error": {
      "anyOf": [
        {
          "type": "string",
          "minLength": 1,
          "maxLength": 512
        },
        {
          "type": "null"
        }
      ]
    },
    "createdAt": {
      "$ref": "common.schema.json#/$defs/Timestamp"
    }
  },
  "required": [
    "id",
    "versionId",
    "kind",
    "recipe",
    "toolchain",
    "profile",
    "sha256",
    "sizeBytes",
    "mediaType",
    "meta",
    "state",
    "error",
    "createdAt"
  ],
  "$defs": {
    "RenditionMeta": {
      "title": "RenditionMeta",
      "description": "Facts a client needs before fetching the bytes.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "width": {
          "type": "integer",
          "minimum": 1,
          "maximum": 16384
        },
        "height": {
          "type": "integer",
          "minimum": 1,
          "maximum": 16384
        },
        "durationMs": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "sampleRate": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000
        },
        "channels": {
          "type": "integer",
          "minimum": 1,
          "maximum": 64
        },
        "points": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000,
          "description": "Peak pairs per channel."
        },
        "resolutions": {
          "type": "array",
          "maxItems": 16,
          "uniqueItems": true,
          "items": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000000
          }
        },
        "page": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100000
        },
        "pages": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100000
        },
        "loudnessLufs": {
          "type": "number",
          "minimum": -100,
          "maximum": 10
        },
        "truncated": {
          "type": "boolean",
          "description": "The preview was cut to the non-reusable cap."
        }
      }
    }
  }
}
