{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tune.toys/schemas/platform/listing-revision.schema.json",
  "title": "ListingRevisionContent",
  "description": "Content of one product listing revision. The effective value of a field is overrides[field] ?? generated[field].",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "generated",
    "overrides",
    "bodyMd",
    "gallery",
    "trailer",
    "manuals",
    "seo"
  ],
  "properties": {
    "generated": {
      "$ref": "#/$defs/ListingFields"
    },
    "overrides": {
      "$ref": "#/$defs/ListingOverrides"
    },
    "bodyMd": {
      "type": "string",
      "maxLength": 65536,
      "description": "Creator Markdown body, sanitized on render; empty until authored."
    },
    "gallery": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/GalleryCarousel"
      },
      "maxItems": 6,
      "description": "Ordered carousels. At most 40 items across all carousels (service rule)."
    },
    "trailer": {
      "anyOf": [
        {
          "$ref": "#/$defs/TrailerItem"
        },
        {
          "type": "null"
        }
      ]
    },
    "manuals": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ManualReference"
      },
      "maxItems": 20,
      "uniqueItems": true
    },
    "seo": {
      "$ref": "#/$defs/ListingSeo"
    }
  },
  "$defs": {
    "ListingFields": {
      "title": "ListingFields",
      "description": "Generated baseline derived from the current stable version.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "tagline": {
          "type": "string",
          "maxLength": 140
        },
        "description": {
          "type": "string",
          "maxLength": 500
        },
        "category": {
          "type": "string",
          "minLength": 1,
          "maxLength": 48,
          "pattern": "^[a-z][a-z0-9-]{0,47}$"
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 32
          },
          "maxItems": 12,
          "uniqueItems": true
        },
        "controls": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ControlSummary"
          },
          "maxItems": 64
        },
        "requirements": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/RequirementSummary"
          },
          "maxItems": 16
        },
        "links": {
          "type": "array",
          "items": {
            "$ref": "common.schema.json#/$defs/ExternalLink"
          },
          "maxItems": 12
        }
      },
      "required": [
        "title",
        "tagline",
        "description",
        "tags",
        "controls",
        "requirements",
        "links"
      ]
    },
    "ListingOverrides": {
      "title": "ListingOverrides",
      "description": "Per-field creator values. Controls and requirements are factual: creators append notes instead of replacing them.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "tagline": {
          "type": "string",
          "maxLength": 140
        },
        "description": {
          "type": "string",
          "maxLength": 500
        },
        "category": {
          "type": "string",
          "minLength": 1,
          "maxLength": 48,
          "pattern": "^[a-z][a-z0-9-]{0,47}$"
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 32
          },
          "maxItems": 12,
          "uniqueItems": true
        },
        "links": {
          "type": "array",
          "items": {
            "$ref": "common.schema.json#/$defs/ExternalLink"
          },
          "maxItems": 12
        },
        "controlsNotesMd": {
          "type": "string",
          "maxLength": 4096
        },
        "requirementsNotesMd": {
          "type": "string",
          "maxLength": 4096
        }
      }
    },
    "ControlSummary": {
      "title": "ControlSummary",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "kind": {
          "type": "string",
          "minLength": 1,
          "maxLength": 32,
          "pattern": "^[a-z][a-z0-9_-]{0,31}$"
        },
        "description": {
          "type": "string",
          "maxLength": 300
        }
      },
      "required": ["label", "kind"]
    },
    "RequirementSummary": {
      "title": "RequirementSummary",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "detail": {
          "type": "string",
          "maxLength": 500
        }
      },
      "required": ["label"]
    },
    "GalleryCarousel": {
      "title": "GalleryCarousel",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "key": {
          "type": "string",
          "minLength": 1,
          "maxLength": 32,
          "pattern": "^[a-z][a-z0-9_-]{0,31}$",
          "description": "Carousel key, main or creator-named."
        },
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/GalleryItem"
          },
          "maxItems": 20,
          "minItems": 1,
          "description": "Items in display order."
        }
      },
      "required": ["key", "items"]
    },
    "GalleryItem": {
      "title": "GalleryItem",
      "oneOf": [
        {
          "$ref": "#/$defs/ImageGalleryItem"
        },
        {
          "$ref": "#/$defs/GifGalleryItem"
        },
        {
          "$ref": "#/$defs/VideoGalleryItem"
        },
        {
          "$ref": "#/$defs/AudioGalleryItem"
        },
        {
          "$ref": "#/$defs/YouTubeGalleryItem"
        },
        {
          "$ref": "#/$defs/VimeoGalleryItem"
        }
      ]
    },
    "TrailerItem": {
      "title": "TrailerItem",
      "description": "The single trailer slot shown first and larger.",
      "oneOf": [
        {
          "$ref": "#/$defs/VideoGalleryItem"
        },
        {
          "$ref": "#/$defs/YouTubeGalleryItem"
        },
        {
          "$ref": "#/$defs/VimeoGalleryItem"
        },
        {
          "$ref": "#/$defs/GifGalleryItem"
        }
      ]
    },
    "ImageGalleryItem": {
      "title": "ImageGalleryItem",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "common.schema.json#/$defs/EntityId",
          "description": "Durable item identity within the listing."
        },
        "caption": {
          "type": "string",
          "maxLength": 200
        },
        "origin": {
          "enum": ["generated", "uploaded"]
        },
        "kind": {
          "const": "image"
        },
        "source": {
          "$ref": "#/$defs/MediaSource"
        },
        "alt": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        }
      },
      "required": ["id", "kind", "source", "alt"]
    },
    "GifGalleryItem": {
      "title": "GifGalleryItem",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "common.schema.json#/$defs/EntityId",
          "description": "Durable item identity within the listing."
        },
        "caption": {
          "type": "string",
          "maxLength": 200
        },
        "origin": {
          "enum": ["generated", "uploaded"]
        },
        "kind": {
          "const": "gif"
        },
        "source": {
          "$ref": "#/$defs/MediaSource"
        },
        "alt": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        }
      },
      "required": ["id", "kind", "source", "alt"]
    },
    "VideoGalleryItem": {
      "title": "VideoGalleryItem",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "common.schema.json#/$defs/EntityId",
          "description": "Durable item identity within the listing."
        },
        "caption": {
          "type": "string",
          "maxLength": 200
        },
        "origin": {
          "enum": ["generated", "uploaded"]
        },
        "kind": {
          "const": "video"
        },
        "source": {
          "$ref": "#/$defs/MediaSource"
        },
        "alt": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300,
          "description": "Alternative text of the poster."
        },
        "posterAssetId": {
          "$ref": "common.schema.json#/$defs/EntityId"
        },
        "transcript": {
          "type": "string",
          "minLength": 1,
          "maxLength": 20000
        },
        "captionsMediaId": {
          "$ref": "common.schema.json#/$defs/EntityId"
        }
      },
      "required": ["id", "kind", "source", "alt"],
      "anyOf": [
        {
          "required": ["transcript"],
          "properties": {
            "transcript": true
          }
        },
        {
          "required": ["captionsMediaId"],
          "properties": {
            "captionsMediaId": true
          }
        }
      ]
    },
    "AudioGalleryItem": {
      "title": "AudioGalleryItem",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "common.schema.json#/$defs/EntityId",
          "description": "Durable item identity within the listing."
        },
        "caption": {
          "type": "string",
          "maxLength": 200
        },
        "origin": {
          "enum": ["generated", "uploaded"]
        },
        "kind": {
          "const": "audio"
        },
        "source": {
          "$ref": "#/$defs/MediaSource"
        },
        "alt": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300,
          "description": "Text description of the audio."
        },
        "transcript": {
          "type": "string",
          "minLength": 1,
          "maxLength": 20000
        },
        "captionsMediaId": {
          "$ref": "common.schema.json#/$defs/EntityId"
        },
        "decorative": {
          "type": "boolean"
        }
      },
      "required": ["id", "kind", "source", "alt"],
      "anyOf": [
        {
          "required": ["transcript"],
          "properties": {
            "transcript": true
          }
        },
        {
          "required": ["captionsMediaId"],
          "properties": {
            "captionsMediaId": true
          }
        },
        {
          "required": ["decorative"],
          "properties": {
            "decorative": {
              "const": true
            }
          }
        }
      ]
    },
    "YouTubeGalleryItem": {
      "title": "YouTubeGalleryItem",
      "description": "Stores only the canonical video ID; rendered through youtube-nocookie with a click-to-load poster.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "common.schema.json#/$defs/EntityId",
          "description": "Durable item identity within the listing."
        },
        "caption": {
          "type": "string",
          "maxLength": 200
        },
        "origin": {
          "enum": ["generated", "uploaded"]
        },
        "kind": {
          "const": "youtube"
        },
        "videoId": {
          "type": "string",
          "minLength": 11,
          "maxLength": 11,
          "pattern": "^[A-Za-z0-9_-]{11}$"
        },
        "alt": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300,
          "description": "Alternative text of the poster."
        },
        "posterAssetId": {
          "$ref": "common.schema.json#/$defs/EntityId"
        }
      },
      "required": ["id", "kind", "videoId", "alt"]
    },
    "VimeoGalleryItem": {
      "title": "VimeoGalleryItem",
      "description": "Stores only the canonical video ID; rendered with dnt=1 and a click-to-load poster.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "common.schema.json#/$defs/EntityId",
          "description": "Durable item identity within the listing."
        },
        "caption": {
          "type": "string",
          "maxLength": 200
        },
        "origin": {
          "enum": ["generated", "uploaded"]
        },
        "kind": {
          "const": "vimeo"
        },
        "videoId": {
          "type": "string",
          "minLength": 6,
          "maxLength": 12,
          "pattern": "^[0-9]{6,12}$"
        },
        "alt": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300,
          "description": "Alternative text of the poster."
        },
        "posterAssetId": {
          "$ref": "common.schema.json#/$defs/EntityId"
        }
      },
      "required": ["id", "kind", "videoId", "alt"]
    },
    "ManualReference": {
      "title": "ManualReference",
      "description": "Ordered reference to a listing document.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "documentId": {
          "$ref": "common.schema.json#/$defs/EntityId"
        },
        "kind": {
          "$ref": "enums.schema.json#/$defs/ListingDocumentKind"
        }
      },
      "required": ["documentId", "kind"]
    },
    "ListingSeo": {
      "title": "ListingSeo",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 70
        },
        "description": {
          "type": "string",
          "maxLength": 160
        },
        "imageAssetId": {
          "$ref": "common.schema.json#/$defs/EntityId"
        }
      }
    },
    "MediaSource": {
      "title": "MediaSource",
      "description": "Uploaded files reference an approved media library item or a listing asset row.",
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["mediaId"],
          "properties": {
            "mediaId": {
              "$ref": "common.schema.json#/$defs/EntityId"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["assetId"],
          "properties": {
            "assetId": {
              "$ref": "common.schema.json#/$defs/EntityId"
            }
          }
        }
      ]
    }
  }
}
