{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tune.toys/schemas/platform/storefront-revision.schema.json",
  "title": "StorefrontRevisionContent",
  "description": "Content of one publisher storefront revision: validated theme tokens and ordered typed sections. Storefronts are data, never code.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "theme": {
      "$ref": "#/$defs/StorefrontTheme"
    },
    "sections": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/StorefrontSection"
      },
      "maxItems": 20
    }
  },
  "required": ["theme", "sections"],
  "$defs": {
    "StorefrontPalette": {
      "title": "StorefrontPalette",
      "description": "sRGB hex colors; the server rejects text/background and accentText/accent below 4.5:1 contrast.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "background": {
          "type": "string",
          "minLength": 7,
          "maxLength": 7,
          "pattern": "^#[0-9a-fA-F]{6}$"
        },
        "surface": {
          "type": "string",
          "minLength": 7,
          "maxLength": 7,
          "pattern": "^#[0-9a-fA-F]{6}$"
        },
        "text": {
          "type": "string",
          "minLength": 7,
          "maxLength": 7,
          "pattern": "^#[0-9a-fA-F]{6}$"
        },
        "accent": {
          "type": "string",
          "minLength": 7,
          "maxLength": 7,
          "pattern": "^#[0-9a-fA-F]{6}$"
        },
        "accentText": {
          "type": "string",
          "minLength": 7,
          "maxLength": 7,
          "pattern": "^#[0-9a-fA-F]{6}$"
        }
      },
      "required": ["background", "surface", "text", "accent", "accentText"]
    },
    "StorefrontTheme": {
      "title": "StorefrontTheme",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "colorScheme": {
          "enum": ["light", "dark", "auto"]
        },
        "light": {
          "$ref": "#/$defs/StorefrontPalette"
        },
        "dark": {
          "$ref": "#/$defs/StorefrontPalette"
        },
        "typography": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "fontPreset": {
              "enum": ["brand", "system-sans", "system-serif", "system-mono"]
            },
            "scale": {
              "enum": ["compact", "default", "large"]
            }
          },
          "required": ["fontPreset", "scale"]
        },
        "shape": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "radius": {
              "enum": ["none", "sm", "md", "lg"]
            },
            "density": {
              "enum": ["compact", "default", "comfortable"]
            }
          },
          "required": ["radius", "density"]
        },
        "heroImage": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "mediaId": {
              "$ref": "common.schema.json#/$defs/EntityId"
            },
            "alt": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "focalPoint": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "x": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                },
                "y": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                }
              },
              "required": ["x", "y"]
            }
          },
          "required": ["mediaId", "alt", "focalPoint"]
        }
      },
      "required": ["colorScheme", "typography", "shape"],
      "allOf": [
        {
          "if": {
            "properties": {
              "colorScheme": {
                "const": "light"
              }
            }
          },
          "then": {
            "required": ["light"],
            "properties": {
              "light": true
            }
          }
        },
        {
          "if": {
            "properties": {
              "colorScheme": {
                "const": "dark"
              }
            }
          },
          "then": {
            "required": ["dark"],
            "properties": {
              "dark": true
            }
          }
        },
        {
          "if": {
            "properties": {
              "colorScheme": {
                "const": "auto"
              }
            }
          },
          "then": {
            "required": ["light", "dark"],
            "properties": {
              "light": true,
              "dark": true
            }
          }
        }
      ]
    },
    "StorefrontSection": {
      "title": "StorefrontSection",
      "oneOf": [
        {
          "$ref": "#/$defs/HeroSection"
        },
        {
          "$ref": "#/$defs/FeaturedSection"
        },
        {
          "$ref": "#/$defs/ProductGridSection"
        },
        {
          "$ref": "#/$defs/BundleSection"
        },
        {
          "$ref": "#/$defs/CollectionSection"
        },
        {
          "$ref": "#/$defs/MarkdownSection"
        },
        {
          "$ref": "#/$defs/VideoSection"
        },
        {
          "$ref": "#/$defs/LinksSection"
        }
      ]
    },
    "HeroSection": {
      "title": "HeroSection",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "common.schema.json#/$defs/EntityId"
        },
        "type": {
          "const": "hero"
        },
        "visible": {
          "type": "boolean"
        },
        "props": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "title": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            },
            "subtitle": {
              "type": "string",
              "maxLength": 200
            },
            "imageMediaId": {
              "$ref": "common.schema.json#/$defs/EntityId"
            },
            "alt": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "primaryAction": {
              "oneOf": [
                {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "productId": {
                      "$ref": "common.schema.json#/$defs/EntityId"
                    }
                  },
                  "required": ["productId"]
                },
                {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "path": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 512,
                      "pattern": "^/[^\\s]*$",
                      "description": "Internal same-origin link."
                    }
                  },
                  "required": ["path"]
                }
              ]
            }
          },
          "required": ["title"]
        }
      },
      "required": ["id", "type", "visible", "props"]
    },
    "FeaturedSection": {
      "title": "FeaturedSection",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "common.schema.json#/$defs/EntityId"
        },
        "type": {
          "const": "featured"
        },
        "visible": {
          "type": "boolean"
        },
        "props": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "productIds": {
              "type": "array",
              "items": {
                "$ref": "common.schema.json#/$defs/EntityId"
              },
              "maxItems": 6,
              "minItems": 1,
              "uniqueItems": true
            },
            "layout": {
              "enum": ["spotlight", "row"]
            }
          },
          "required": ["productIds", "layout"]
        }
      },
      "required": ["id", "type", "visible", "props"]
    },
    "ProductGridSection": {
      "title": "ProductGridSection",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "common.schema.json#/$defs/EntityId"
        },
        "type": {
          "const": "product_grid"
        },
        "visible": {
          "type": "boolean"
        },
        "props": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "source": {
              "enum": ["all", "kind", "tag", "manual"]
            },
            "kind": {
              "$ref": "enums.schema.json#/$defs/ProductKind"
            },
            "tag": {
              "type": "string",
              "minLength": 1,
              "maxLength": 32
            },
            "productIds": {
              "type": "array",
              "items": {
                "$ref": "common.schema.json#/$defs/EntityId"
              },
              "maxItems": 48,
              "uniqueItems": true
            },
            "sort": {
              "enum": ["recent", "title", "rating"]
            },
            "limit": {
              "type": "integer",
              "minimum": 1,
              "maximum": 48
            }
          },
          "required": ["source", "sort", "limit"]
        }
      },
      "required": ["id", "type", "visible", "props"]
    },
    "BundleSection": {
      "title": "BundleSection",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "common.schema.json#/$defs/EntityId"
        },
        "type": {
          "const": "bundle"
        },
        "visible": {
          "type": "boolean"
        },
        "props": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "productId": {
              "$ref": "common.schema.json#/$defs/EntityId"
            }
          },
          "required": ["productId"]
        }
      },
      "required": ["id", "type", "visible", "props"]
    },
    "CollectionSection": {
      "title": "CollectionSection",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "common.schema.json#/$defs/EntityId"
        },
        "type": {
          "const": "collection"
        },
        "visible": {
          "type": "boolean"
        },
        "props": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "title": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            },
            "productIds": {
              "type": "array",
              "items": {
                "$ref": "common.schema.json#/$defs/EntityId"
              },
              "maxItems": 24,
              "minItems": 1,
              "uniqueItems": true
            }
          },
          "required": ["title", "productIds"]
        }
      },
      "required": ["id", "type", "visible", "props"]
    },
    "MarkdownSection": {
      "title": "MarkdownSection",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "common.schema.json#/$defs/EntityId"
        },
        "type": {
          "const": "markdown"
        },
        "visible": {
          "type": "boolean"
        },
        "props": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "bodyMd": {
              "type": "string",
              "minLength": 1,
              "maxLength": 16384
            }
          },
          "required": ["bodyMd"]
        }
      },
      "required": ["id", "type", "visible", "props"]
    },
    "VideoSection": {
      "title": "VideoSection",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "common.schema.json#/$defs/EntityId"
        },
        "type": {
          "const": "video"
        },
        "visible": {
          "type": "boolean"
        },
        "props": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "item": {
              "oneOf": [
                {
                  "$ref": "listing-revision.schema.json#/$defs/VideoGalleryItem"
                },
                {
                  "$ref": "listing-revision.schema.json#/$defs/YouTubeGalleryItem"
                },
                {
                  "$ref": "listing-revision.schema.json#/$defs/VimeoGalleryItem"
                }
              ]
            }
          },
          "required": ["item"]
        }
      },
      "required": ["id", "type", "visible", "props"]
    },
    "LinksSection": {
      "title": "LinksSection",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "common.schema.json#/$defs/EntityId"
        },
        "type": {
          "const": "links"
        },
        "visible": {
          "type": "boolean"
        },
        "props": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "links": {
              "type": "array",
              "items": {
                "$ref": "common.schema.json#/$defs/ExternalLink"
              },
              "maxItems": 12,
              "minItems": 1
            }
          },
          "required": ["links"]
        }
      },
      "required": ["id", "type", "visible", "props"]
    }
  }
}
