{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://draftwright.dev/schema/draftwright-replay-assessment-v2.schema.json",
  "title": "Draftwright generated-script replay assessment v2",
  "description": "The strict declared drawing, confirmed compiled measurements, and exact file identities produced by one successful generated-script replay.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "schema_version", "scope", "status", "producer", "source", "script", "run", "outputs", "semantic_links", "measurements", "drawing"],
  "properties": {
    "schema": { "const": "draftwright-replay-assessment" },
    "schema_version": { "const": 2 },
    "scope": { "const": "generated-script-replay" },
    "status": { "enum": ["bounded-clear", "needs-attention"] },
    "producer": {
      "type": "object",
      "additionalProperties": false,
      "required": ["draftwright", "quiddity"],
      "properties": {
        "draftwright": { "type": "string", "minLength": 1 },
        "quiddity": { "type": "string", "minLength": 1 }
      }
    },
    "source": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "name", "sha256", "reason"],
          "properties": {
            "kind": { "const": "step" },
            "name": { "type": "string", "minLength": 1 },
            "sha256": { "$ref": "#/$defs/sha256" },
            "reason": { "type": "null" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "name", "sha256", "reason"],
          "properties": {
            "kind": { "const": "build123d" },
            "name": { "type": "null" },
            "sha256": { "type": "null" },
            "reason": { "type": "string", "minLength": 1 }
          }
        }
      ]
    },
    "script": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "sha256"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "sha256": { "$ref": "#/$defs/sha256" }
      }
    },
    "run": {
      "type": "object",
      "additionalProperties": false,
      "required": ["pmi_mode", "formats", "reproducible"],
      "properties": {
        "pmi_mode": { "enum": ["off", "report", "annotate"] },
        "formats": {
          "type": "array",
          "items": { "enum": ["svg", "dxf", "pdf", "png"] },
          "uniqueItems": true
        },
        "reproducible": { "type": "boolean" }
      }
    },
    "outputs": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["format", "path", "sha256", "bytes"],
        "properties": {
          "format": { "enum": ["svg", "dxf", "pdf", "png"] },
          "path": { "type": "string", "minLength": 1 },
          "sha256": { "$ref": "#/$defs/sha256" },
          "bytes": { "type": "integer", "minimum": 0 }
        }
      }
    },
    "semantic_links": {
      "type": "object",
      "additionalProperties": false,
      "required": ["authority", "declarations", "representations", "identity_scope"],
      "properties": {
        "authority": { "const": "drawing.declarations" },
        "declarations": { "const": "drawing.declarations.entries[].id" },
        "representations": { "const": "drawing.declarations.entries[].representations[].name" },
        "identity_scope": { "const": "build-local" }
      }
    },
    "measurements": {
      "type": "object",
      "additionalProperties": false,
      "required": ["authority", "identity_scope", "entries", "unknown", "unavailable_owner_claims"],
      "properties": {
        "authority": { "const": "confirmed-compiled-claims" },
        "identity_scope": { "const": "build-local-declarations" },
        "entries": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["declaration_id", "owner_id", "parameter_id", "annotation", "cell", "meaning", "rendered", "witnesses", "verification"],
            "properties": {
              "declaration_id": { "type": "string", "minLength": 1 },
              "owner_id": { "type": "string", "minLength": 1 },
              "parameter_id": { "type": "string", "minLength": 1 },
              "annotation": { "type": "string", "minLength": 1 },
              "cell": {
                "oneOf": [
                  { "type": "null" },
                  {
                    "type": "object",
                    "additionalProperties": false,
                    "required": ["row", "column"],
                    "properties": {
                      "row": { "type": "integer", "minimum": 1 },
                      "column": { "type": "integer", "minimum": 0 }
                    }
                  }
                ]
              },
              "meaning": {
                "type": "array",
                "minItems": 1,
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["value", "tolerance", "span", "axis", "discriminator", "location_member", "angular_reference"],
                  "properties": {
                    "value": {}, "tolerance": {}, "span": {}, "axis": {},
                    "discriminator": {}, "location_member": {}, "angular_reference": {}
                  }
                }
              },
              "rendered": { "type": "array" },
              "witnesses": { "type": "array" },
              "verification": { "const": "confirmed-within-measurement-verifier-scope" }
            }
          }
        },
        "unknown": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["annotation", "reason"],
            "properties": {
              "annotation": { "type": "string" },
              "reason": { "type": "string", "minLength": 1 },
              "cell": {
                "type": "object",
                "additionalProperties": false,
                "required": ["row", "column"],
                "properties": {
                  "row": { "type": "integer", "minimum": 1 },
                  "column": { "type": "integer", "minimum": 0 }
                }
              }
            }
          }
        },
        "unavailable_owner_claims": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["annotation", "parameter_id", "reason"],
            "properties": {
              "annotation": { "type": "string", "minLength": 1 },
              "parameter_id": { "type": "string", "minLength": 1 },
              "reason": { "type": "string", "minLength": 1 }
            }
          }
        }
      }
    },
    "drawing": { "$ref": "https://draftwright.dev/schema/draftwright-report-v8.schema.json" }
  },
  "$defs": {
    "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
  }
}
