{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "kicad_cruncher.toon_manifest.a0",
  "title": "KiCad Cruncher Toon Manifest",
  "description": "Portable artifact index emitted by the Python and native toon commands.",
  "type": "object",
  "required": [
    "schema",
    "version",
    "source",
    "requested_sides",
    "selection",
    "variant_selection",
    "presentation",
    "config",
    "geometer",
    "artifacts"
  ],
  "properties": {
    "schema": {"const": "kicad_cruncher.toon_manifest.a0"},
    "version": {"const": "a0"},
    "source": {
      "type": "string",
      "minLength": 1,
      "pattern": "^(?![A-Za-z]:)(?!/)(?!.*[\\\\/]).+$"
    },
    "requested_sides": {"enum": ["top", "bottom", "both"]},
    "selection": {"$ref": "#/$defs/selection"},
    "variant_selection": {"$ref": "#/$defs/variant_selection"},
    "presentation": {"$ref": "#/$defs/presentation"},
    "config": {"$ref": "#/$defs/config"},
    "geometer": {"$ref": "#/$defs/geometer"},
    "artifacts": {
      "type": "array",
      "minItems": 1,
      "maxItems": 512,
      "items": {"$ref": "#/$defs/artifact"}
    }
  },
  "additionalProperties": false,
  "$defs": {
    "sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "selection": {
      "oneOf": [
        {
          "type": "object",
          "required": ["kind"],
          "properties": {"kind": {"const": "board"}},
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["kind", "reference"],
          "properties": {
            "kind": {"const": "footprint"},
            "reference": {"type": "string", "minLength": 1}
          },
          "additionalProperties": false
        }
      ]
    },
    "variant_selection": {
      "oneOf": [
        {
          "type": "object",
          "required": ["mode"],
          "properties": {"mode": {"enum": ["base", "all"]}},
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["mode", "name"],
          "properties": {
            "mode": {"const": "named"},
            "name": {"type": "string", "minLength": 1}
          },
          "additionalProperties": false
        }
      ]
    },
    "geometer": {
      "type": "object",
      "required": ["release", "c_abi_generation", "source_revision"],
      "properties": {
        "release": {"const": "2026.11.22"},
        "c_abi_generation": {"const": 20261122},
        "source_revision": {
          "const": "1dd57397486dc4bb28c206fb00c25cbf8f79e233"
        }
      },
      "additionalProperties": false
    },
    "presentation": {
      "type": "object",
      "required": ["theme", "assembly_designators", "sides"],
      "properties": {
        "theme": {
          "enum": [
            "saved",
            "white",
            "black",
            "blue",
            "red",
            "purple",
            "yellow",
            "green",
            "config",
            "custom"
          ]
        },
        "assembly_designators": {"type": "boolean"},
        "sides": {
          "type": "object",
          "required": ["top", "bottom"],
          "properties": {
            "top": {"$ref": "#/$defs/presentation_side"},
            "bottom": {"$ref": "#/$defs/presentation_side"}
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "presentation_side": {
      "type": "object",
      "required": ["soldermask_color", "silkscreen_color"],
      "properties": {
        "soldermask_color": {
          "type": "string",
          "pattern": "^(?:auto|#[0-9A-Fa-f]{6})$"
        },
        "silkscreen_color": {
          "type": "string",
          "pattern": "^(?:contrast|#[0-9A-Fa-f]{6})$"
        }
      },
      "additionalProperties": false
    },
    "config": {
      "type": "object",
      "required": ["file", "resolved_sha256"],
      "properties": {
        "file": {
          "type": "string",
          "minLength": 1,
          "pattern": "^(?![A-Za-z]:)(?!/)(?!.*[\\\\/]).+$"
        },
        "resolved_sha256": {"$ref": "#/$defs/sha256"}
      },
      "additionalProperties": false
    },
    "artifact": {
      "type": "object",
      "required": [
        "file",
        "variant",
        "side",
        "svg_bytes",
        "svg_sha256",
        "soldermask_color",
        "silkscreen_color",
        "rendered_model_count",
        "geometer_request_count",
        "model_cache_hit_count",
        "persistent_model_cache_hit_count",
        "warnings"
      ],
      "properties": {
        "file": {
          "type": "string",
          "minLength": 1,
          "pattern": "^(?![A-Za-z]:)(?!/)(?!.*\\\\)(?!.*(?:^|/)\\.\\.?(?:/|$))(?:[^/]+/)*[^/]+\\.svg$"
        },
        "variant": {"type": "string", "minLength": 1},
        "side": {"enum": ["top", "bottom"]},
        "svg_bytes": {"type": "integer", "minimum": 1},
        "svg_sha256": {"$ref": "#/$defs/sha256"},
        "soldermask_color": {
          "type": "string",
          "pattern": "^#[0-9A-Fa-f]{6}$"
        },
        "silkscreen_color": {
          "type": "string",
          "pattern": "^#[0-9A-Fa-f]{6}$"
        },
        "rendered_model_count": {"type": "integer", "minimum": 0},
        "geometer_request_count": {"type": "integer", "minimum": 0},
        "model_cache_hit_count": {"type": "integer", "minimum": 0},
        "persistent_model_cache_hit_count": {"type": "integer", "minimum": 0},
        "warnings": {
          "type": "array",
          "items": {"type": "string"}
        }
      },
      "additionalProperties": false
    }
  }
}
