{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Reference Registry",
  "description": "Schema for visual reference registry used in long-form video generation",
  "type": "object",
  "required": ["version", "categories"],
  "properties": {
    "version": {
      "type": "string",
      "description": "Schema version"
    },
    "last_updated": {
      "type": "string",
      "format": "date",
      "description": "Last update date"
    },
    "description": {
      "type": "string"
    },
    "categories": {
      "type": "object",
      "properties": {
        "characters": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/definitions/character"
          }
        },
        "locations": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/definitions/location"
          }
        },
        "props": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/definitions/prop"
          }
        }
      }
    }
  },
  "definitions": {
    "character": {
      "type": "object",
      "required": ["id", "name"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^char_",
          "description": "Unique character ID"
        },
        "name": {
          "type": "string",
          "description": "Character display name"
        },
        "visual_anchor": {
          "type": ["string", "null"],
          "description": "Actor/reference base for this character"
        },
        "description": {
          "type": "string"
        },
        "attributes": {
          "type": "object",
          "properties": {
            "build": {
              "type": "string"
            },
            "skin": {
              "type": "string"
            },
            "hair": {
              "type": "string"
            },
            "distinctive_features": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "costumes": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "description": {
                "type": "string"
              },
              "references": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          }
        },
        "reference_images": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/reference_image"
          }
        }
      }
    },
    "location": {
      "type": "object",
      "required": ["id", "name"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^loc_"
        },
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "visual_style": {
          "type": "object",
          "properties": {
            "lighting": {
              "type": "string"
            },
            "palette": {
              "type": "string"
            }
          }
        },
        "canonical_frame": {
          "type": ["string", "null"],
          "description": "Path to the canonical reference frame for this location"
        },
        "reference_images": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/reference_image"
          }
        }
      }
    },
    "prop": {
      "type": "object",
      "required": ["id", "name"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^prop_"
        },
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "reference_images": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/reference_image"
          }
        }
      }
    },
    "reference_image": {
      "type": "object",
      "required": ["path", "type"],
      "properties": {
        "path": {
          "type": "string",
          "description": "Relative path from assets/references/"
        },
        "type": {
          "type": "string",
          "enum": [
            "face_portrait",
            "full_body",
            "costume_detail",
            "location_wide",
            "prop_detail",
            "character_sheet"
          ],
          "description": "Type of reference"
        },
        "usage": {
          "type": "string",
          "description": "How this reference should be used"
        },
        "face_region": {
          "$ref": "#/definitions/bounding_box",
          "description": "Face bounding box coordinates"
        },
        "annotated_version": {
          "type": "string",
          "description": "Path to annotated version (temporary, can be cleaned up)"
        },
        "temporary": {
          "type": "boolean",
          "default": false,
          "description": "If true, this annotated image can be cleaned up"
        },
        "source_research": {
          "type": ["string", "null"],
          "description": "Path to the original research source file in assets/references/research/ that was used to generate this production reference."
        }
      }
    },
    "bounding_box": {
      "type": "object",
      "required": ["x1", "y1", "x2", "y2"],
      "properties": {
        "x1": {
          "type": "integer",
          "description": "Top-left X"
        },
        "y1": {
          "type": "integer",
          "description": "Top-left Y"
        },
        "x2": {
          "type": "integer",
          "description": "Bottom-right X"
        },
        "y2": {
          "type": "integer",
          "description": "Bottom-right Y"
        }
      }
    }
  }
}
