{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://draftwright.dev/schema/draftwright-report-v3.schema.json",
  "title": "Draftwright report v3",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "schema_version",
    "status",
    "producer",
    "source",
    "outputs",
    "recognition",
    "lint"
  ],
  "properties": {
    "schema": {
      "const": "draftwright-report"
    },
    "schema_version": {
      "const": 3
    },
    "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": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "name"
      ],
      "properties": {
        "kind": {
          "enum": [
            "build123d",
            "step"
          ]
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "outputs": {
      "type": "object",
      "description": "Reserved for the later sidecar/export integration."
    },
    "recognition": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "coverage",
        "identity_scope",
        "occurrences",
        "requirements",
        "summary",
        "owners"
      ],
      "properties": {
        "coverage": {
          "const": "accepted-occurrences-and-profile-requirements"
        },
        "identity_scope": {
          "const": "report-local"
        },
        "occurrences": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/occurrence"
          }
        },
        "requirements": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/requirement_outcome"
          }
        },
        "summary": {
          "$ref": "#/$defs/summary"
        },
        "owners": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/owner"
          }
        }
      }
    },
    "lint": {
      "type": "object",
      "description": "The existing Drawing.lint_summary() JSON contract."
    }
  },
  "$defs": {
    "owner": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "kind"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "kind": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "requirement_refs": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "coverage",
        "ids"
      ],
      "properties": {
        "coverage": {
          "enum": [
            "ledger",
            "not-projected",
            "not-applicable",
            "deferred",
            "unavailable"
          ]
        },
        "ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        }
      }
    },
    "requirement_outcome": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "family",
        "occurrence_ids",
        "owner_ids",
        "parameter_id",
        "state",
        "reason_code",
        "annotations",
        "representation",
        "representation_reason"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "family": {
          "type": "string",
          "minLength": 1
        },
        "occurrence_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "owner_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "parameter_id": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1
        },
        "state": {
          "enum": [
            "placed",
            "satisfied_by_structured_note",
            "suppressed",
            "dropped",
            "missing",
            "unverifiable",
            "unsupported"
          ]
        },
        "reason_code": {
          "type": "string",
          "minLength": 1
        },
        "annotations": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "representation": {
          "type": [
            "string",
            "null"
          ]
        },
        "representation_reason": {
          "type": [
            "string",
            "null"
          ]
        },
        "profile_source": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind",
            "profile_id",
            "support_ids"
          ],
          "properties": {
            "kind": {
              "const": "planar_outer_profile"
            },
            "profile_id": {
              "type": "string",
              "pattern": "^profile:[1-9][0-9]*$"
            },
            "support_ids": {
              "type": "array",
              "minItems": 2,
              "maxItems": 2,
              "uniqueItems": true,
              "items": {
                "type": "string",
                "pattern": "^support:[1-9][0-9]*$"
              }
            }
          }
        }
      },
      "oneOf": [
        {
          "not": {
            "required": [
              "profile_source"
            ]
          },
          "properties": {
            "occurrence_ids": {
              "minItems": 1
            },
            "family": {
              "not": {
                "const": "outer_profile_angles"
              }
            }
          }
        },
        {
          "required": [
            "profile_source"
          ],
          "properties": {
            "family": {
              "const": "outer_profile_angles"
            },
            "occurrence_ids": {
              "maxItems": 0
            }
          }
        }
      ]
    },
    "occurrence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "family",
        "record_type",
        "record_schema_version",
        "record",
        "disposition",
        "reason_code",
        "tracking",
        "owners",
        "requirements"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "family": {
          "type": "string",
          "minLength": 1
        },
        "record_type": {
          "type": "string",
          "minLength": 1
        },
        "record_schema_version": {
          "type": "integer",
          "minimum": 1
        },
        "record": {
          "type": "object"
        },
        "disposition": {
          "enum": [
            "represented",
            "absorbed",
            "unsupported",
            "deferred",
            "evidence_only",
            "unexpectedly_missing"
          ]
        },
        "reason_code": {
          "type": "string",
          "minLength": 1
        },
        "tracking": {
          "type": [
            "string",
            "null"
          ]
        },
        "owners": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/owner"
          }
        },
        "requirements": {
          "$ref": "#/$defs/requirement_refs"
        }
      }
    },
    "summary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "total",
        "represented",
        "absorbed",
        "unsupported",
        "deferred",
        "evidence_only",
        "unexpectedly_missing"
      ],
      "properties": {
        "total": {
          "type": "integer",
          "minimum": 0
        },
        "represented": {
          "type": "integer",
          "minimum": 0
        },
        "absorbed": {
          "type": "integer",
          "minimum": 0
        },
        "unsupported": {
          "type": "integer",
          "minimum": 0
        },
        "deferred": {
          "type": "integer",
          "minimum": 0
        },
        "evidence_only": {
          "type": "integer",
          "minimum": 0
        },
        "unexpectedly_missing": {
          "type": "integer",
          "minimum": 0
        }
      }
    }
  }
}
