{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://kaladan.dev/contracts/theme/v1/section.schema.json",
  "title": "sections/*.yaml",
  "description": "One section a merchant can add to a template, and everything the visual builder needs to render an editor for it. The filename is the section's id: sections/hero.yaml declares 'hero'.",
  "type": "object",

  "properties": {
    "name": {
      "$ref": "common.schema.json#/$defs/LocalizedText",
      "description": "What the merchant sees in the section picker."
    },
    "description": {
      "$ref": "common.schema.json#/$defs/LocalizedText",
      "description": "A sentence in the picker. Merchants choose sections by name and description alone, so a section named 'Section 3' will not be used."
    },
    "limit": {
      "type": "integer", "minimum": 1,
      "description": "Maximum instances per template. Omit for unlimited. A hero that may appear once says so, rather than letting a merchant build a page of five and wonder why it looks wrong."
    },
    "tags": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Grouping in the section picker: 'banner', 'product', 'content'."
    },

    "settings": {
      "type": "array",
      "items": { "$ref": "common.schema.json#/$defs/Setting" },
      "description": "The section's own settings. Ids are stable within a major version — see manifest.md."
    },

    "blocks": {
      "type": "array",
      "description": "Repeatable child items the merchant adds, reorders, and removes inside this section: slides, columns, links, feature rows.",
      "items": {
        "type": "object",
        "properties": {
          "type": { "$ref": "common.schema.json#/$defs/Handle" },
          "name": { "$ref": "common.schema.json#/$defs/LocalizedText" },
          "limit": { "type": "integer", "minimum": 1 },
          "settings": {
            "type": "array",
            "items": { "$ref": "common.schema.json#/$defs/Setting" }
          }
        },
        "required": ["type", "name"],
        "additionalProperties": false
      }
    },

    "maxBlocks": {
      "type": "integer", "minimum": 1,
      "description": "Total blocks of any type in one instance of this section."
    },

    "presets": {
      "type": "array",
      "minItems": 1,
      "description": "Starting points offered when the section is added; the first is the default. A section with no preset is added empty, which reads as broken to a merchant who has just chosen it from a picture.",
      "items": {
        "type": "object",
        "properties": {
          "handle": {
            "$ref": "common.schema.json#/$defs/Handle",
            "description": "Optional, and only needed so a starting layout can name this preset rather than taking the first. Unique within the section. Stable once published, for the same reason a setting id is: it is referenced from theme.yaml, and renaming it silently changes what a fresh shop renders."
          },
          "name": { "$ref": "common.schema.json#/$defs/LocalizedText" },
          "settings": { "type": "object" },
          "blocks": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "type": { "$ref": "common.schema.json#/$defs/Handle" },
                "settings": { "type": "object" }
              },
              "required": ["type"],
              "additionalProperties": false
            }
          }
        },
        "required": ["name"],
        "additionalProperties": false
      }
    },

    "appBlocks": {
      "type": "boolean",
      "default": false,
      "description": "Whether a merchant may place a third-party app's block inside this section. When true, the theme MUST render blocks of unrecognised type by emitting their `html`, which is what lets an app block work in a theme whose author has never heard of the app."
    }
  },

  "required": ["name"],
  "additionalProperties": false
}
