{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://visualspec.dev/schema/1.0/modules/references.schema.json",
  "title": "References",
  "description": "Addressable source resources, visual evidence, reference graph and conflict resolution.",
  "$defs": {
    "source": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/id"
        },
        "kind": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/taxonomy"
        },
        "uri": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/uri"
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string",
          "minLength": 1
        },
        "mediaType": {
          "type": "string",
          "minLength": 1
        },
        "checksum": {
          "type": "string",
          "minLength": 1
        },
        "version": {
          "type": "string",
          "minLength": 1
        },
        "license": {
          "type": "string",
          "minLength": 1
        },
        "provenance": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/provenance"
        },
        "extensions": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/extensions"
        }
      },
      "required": [
        "id",
        "kind"
      ],
      "additionalProperties": false
    },
    "locator": {
      "type": "object",
      "properties": {
        "region": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/bounds"
        },
        "dom": {
          "type": "object",
          "properties": {
            "cssSelector": {
              "type": "string",
              "minLength": 1
            },
            "xpath": {
              "type": "string",
              "minLength": 1
            },
            "text": {
              "type": "string",
              "minLength": 1
            },
            "shadowPath": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "additionalProperties": false
        },
        "viewport": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/viewport"
        },
        "figma": {
          "type": "object",
          "properties": {
            "fileKey": {
              "type": "string",
              "minLength": 1
            },
            "nodeId": {
              "type": "string",
              "minLength": 1
            },
            "pageId": {
              "type": "string",
              "minLength": 1
            },
            "version": {
              "type": "string",
              "minLength": 1
            }
          },
          "required": [
            "fileKey",
            "nodeId"
          ],
          "additionalProperties": false
        },
        "pdf": {
          "type": "object",
          "properties": {
            "page": {
              "type": "integer",
              "minimum": 1
            },
            "region": {
              "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/bounds"
            }
          },
          "required": [
            "page"
          ],
          "additionalProperties": false
        },
        "presentation": {
          "type": "object",
          "properties": {
            "slide": {
              "type": "integer",
              "minimum": 1
            },
            "shapeId": {
              "type": "string",
              "minLength": 1
            }
          },
          "required": [
            "slide"
          ],
          "additionalProperties": false
        },
        "video": {
          "type": "object",
          "properties": {
            "start": {
              "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/time"
            },
            "end": {
              "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/time"
            },
            "frame": {
              "type": "integer",
              "minimum": 0
            },
            "track": {
              "type": "integer",
              "minimum": 0
            },
            "fps": {
              "type": "number",
              "exclusiveMinimum": 0
            }
          },
          "additionalProperties": false
        },
        "scene3d": {
          "type": "object",
          "properties": {
            "scene": {
              "type": "string",
              "minLength": 1
            },
            "node": {
              "type": "string",
              "minLength": 1
            },
            "camera": {
              "type": "string",
              "minLength": 1
            },
            "material": {
              "type": "string",
              "minLength": 1
            }
          },
          "additionalProperties": false
        },
        "document": {
          "type": "object",
          "properties": {
            "section": {
              "type": "string",
              "minLength": 1
            },
            "heading": {
              "type": "string",
              "minLength": 1
            },
            "paragraph": {
              "type": "integer",
              "minimum": 1
            },
            "bookmark": {
              "type": "string",
              "minLength": 1
            }
          },
          "additionalProperties": false
        },
        "image": {
          "type": "object",
          "properties": {
            "region": {
              "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/bounds"
            },
            "frame": {
              "type": "integer",
              "minimum": 0
            }
          },
          "additionalProperties": false
        },
        "text": {
          "type": "object",
          "properties": {
            "start": {
              "type": "integer",
              "minimum": 0
            },
            "end": {
              "type": "integer",
              "minimum": 0
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "reference": {
      "type": "object",
      "description": "Evidence may be located externally, but validators must never fetch or execute it implicitly.",
      "properties": {
        "id": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/id"
        },
        "kind": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/taxonomy"
        },
        "role": {
          "enum": [
            "source-of-truth",
            "preferred",
            "supporting",
            "inspiration",
            "avoid"
          ]
        },
        "uri": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/uri"
        },
        "sourceRef": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/id"
        },
        "text": {
          "type": "string",
          "minLength": 1
        },
        "locator": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/references.schema.json#/$defs/locator"
        },
        "aspects": {
          "type": "array",
          "items": {
            "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/taxonomy"
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "weight": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "priority": {
          "type": "integer",
          "minimum": 0
        },
        "confidence": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "provenance": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/provenance"
        },
        "description": {
          "type": "string",
          "minLength": 1
        },
        "referenceRefs": {
          "type": "array",
          "items": {
            "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/id"
          },
          "uniqueItems": true
        },
        "extensions": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/extensions"
        },
        "matchMode": {
          "enum": [
            "exact",
            "structural",
            "perceptual",
            "semantic",
            "stylistic",
            "inspirational"
          ]
        },
        "conformance": {
          "type": "object",
          "additionalProperties": {
            "enum": [
              "strict",
              "approximate",
              "inspiration"
            ]
          }
        },
        "tolerance": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/validation.schema.json#/$defs/tolerance"
        }
      },
      "required": [
        "id",
        "kind",
        "role"
      ],
      "additionalProperties": false
    },
    "binding": {
      "type": "object",
      "properties": {
        "referenceRef": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/id"
        },
        "aspects": {
          "type": "array",
          "items": {
            "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/taxonomy"
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "weight": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "priority": {
          "type": "integer",
          "minimum": 0
        }
      },
      "required": [
        "referenceRef"
      ],
      "additionalProperties": false
    },
    "referenceSet": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/id"
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "references": {
          "type": "array",
          "items": {
            "anyOf": [
              {
                "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/id"
              },
              {
                "$ref": "https://visualspec.dev/schema/1.0/modules/references.schema.json#/$defs/binding"
              }
            ]
          },
          "minItems": 1
        },
        "conflictPolicy": {
          "enum": [
            "priority",
            "first-wins",
            "last-wins",
            "weighted",
            "most-specific",
            "explicit-over-inferred",
            "error"
          ]
        },
        "aspectPriority": {
          "type": "object",
          "additionalProperties": {
            "type": "array",
            "items": {
              "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/id"
            },
            "uniqueItems": true
          }
        },
        "description": {
          "type": "string",
          "minLength": 1
        },
        "extensions": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/extensions"
        }
      },
      "required": [
        "id",
        "references",
        "conflictPolicy"
      ],
      "additionalProperties": false
    },
    "assertion": {
      "type": "object",
      "properties": {
        "path": {
          "type": "string",
          "minLength": 1,
          "description": "JSON Pointer into this document."
        },
        "source": {
          "type": "string",
          "minLength": 1
        },
        "sourceRef": {
          "$ref": "https://visualspec.dev/schema/1.0/modules/common.schema.json#/$defs/id"
        },
        "method": {
          "enum": [
            "direct",
            "derived",
            "inferred",
            "manual",
            "generated",
            "validated",
            "explicit",
            "measured",
            "extracted",
            "vision-inference",
            "reference-derived",
            "defaulted",
            "platform-derived"
          ]
        },
        "confidence": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        }
      },
      "required": [
        "path",
        "method"
      ],
      "additionalProperties": false
    }
  }
}
