{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rodloom.com/agents/design.schema.json",
  "title": "Rod Loom version 1 design authoring contract",
  "description": "Recommended explicit format for agent-created designs. Thread identities must also be checked against assets/catalog.json. See design-guide.md for geometry and legacy import differences.",
  "type": "object",
  "required": ["version", "name", "threadSize", "coverage", "diameter", "blank", "texture", "bands"],
  "properties": {
    "version": {"const": 1},
    "name": {"type": "string", "maxLength": 80},
    "threadSize": {"enum": ["A", "D"]},
    "coverage": {"type": "number", "minimum": 0.05, "maximum": 1},
    "diameter": {"type": "number", "minimum": 1, "maximum": 50},
    "blank": {"$ref": "#/$defs/color"},
    "texture": {"type": "boolean"},
    "bands": {"type": "array", "items": {"$ref": "#/$defs/band"}},
    "quickColors": {"type": "array", "maxItems": 500, "items": {"$ref": "#/$defs/thread"}}
  },
  "$defs": {
    "color": {"type": "string", "pattern": "^#[0-9a-fA-F]{6}$"},
    "thread": {
      "type": "object",
      "required": ["name", "color", "finish", "brand", "sku", "catalog"],
      "properties": {
        "name": {"type": "string", "maxLength": 80},
        "color": {"$ref": "#/$defs/color"},
        "finish": {"enum": ["regular", "metallic", "neon"]},
        "brand": {"enum": ["Fuji", "ProWrap"]},
        "sku": {"type": "string", "minLength": 1, "maxLength": 160},
        "catalog": {"const": true},
        "line": {"type": "string", "maxLength": 160},
        "code": {"type": "string", "maxLength": 160},
        "source": {"type": "string"}
      }
    },
    "band": {
      "allOf": [
        {"$ref": "#/$defs/thread"},
        {
          "type": "object",
          "required": ["turns"],
          "properties": {
            "turns": {"type": "integer", "minimum": 1, "maximum": 1000},
            "wrap": {"enum": ["solid", "spiral"]},
            "secondary": {"$ref": "#/$defs/thread"},
            "direction": {"enum": [1, -1]},
            "group": {"type": "string", "minLength": 1, "maxLength": 80},
            "groupName": {"type": "string", "maxLength": 80}
          },
          "if": {"required": ["wrap"], "properties": {"wrap": {"const": "spiral"}}},
          "then": {"required": ["secondary", "direction"]}
        }
      ]
    }
  }
}
