{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://archsightlabs.github.io/aios/schemas/architecture-health/0.1/input.schema.json",
  "title": "ArchSight AIOS Architecture Health Normalized Input 0.1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "repository", "observedAt", "observations", "dependencies", "evidence"],
  "properties": {
    "schemaVersion": { "const": "0.1" },
    "repository": { "$ref": "#/$defs/repository" },
    "observedAt": { "type": "string", "format": "date-time" },
    "observations": {
      "type": "array",
      "items": { "$ref": "#/$defs/observation" }
    },
    "dependencies": {
      "type": "array",
      "items": { "$ref": "#/$defs/dependency" }
    },
    "evidence": {
      "type": "array",
      "items": { "$ref": "#/$defs/evidence" }
    },
    "constraints": {
      "type": "array",
      "items": { "$ref": "#/$defs/constraint" }
    },
    "analyzers": {
      "type": "array",
      "items": { "$ref": "#/$defs/analyzerState" }
    }
  },
  "$defs": {
    "evidenceClass": {
      "type": "string",
      "enum": ["measured", "inferred", "unverified"]
    },
    "repository": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "commit"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "commit": { "type": "string", "minLength": 1 }
      }
    },
    "location": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path"],
      "properties": {
        "path": { "type": "string", "minLength": 1 },
        "line": { "type": "integer", "minimum": 1 },
        "symbol": { "type": "string", "minLength": 1 }
      }
    },
    "context": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "environment": { "type": "string" },
        "dataset": { "type": "string" },
        "conditions": { "type": "string" },
        "sampleSize": { "type": "integer", "minimum": 1 },
        "databaseVersion": { "type": "string" },
        "hardware": { "type": "string" }
      }
    },
    "observation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "dimension", "metric", "value", "evidenceClass", "message", "source"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "dimension": { "type": "string", "minLength": 1 },
        "metric": { "type": "string", "minLength": 1 },
        "value": { "type": ["number", "string", "boolean"] },
        "unit": { "type": "string" },
        "evidenceClass": { "$ref": "#/$defs/evidenceClass" },
        "location": { "$ref": "#/$defs/location" },
        "message": { "type": "string", "minLength": 1 },
        "source": { "type": "string", "minLength": 1 },
        "context": { "$ref": "#/$defs/context" }
      }
    },
    "dependency": {
      "type": "object",
      "additionalProperties": false,
      "required": ["from", "to", "fromLayer", "toLayer", "evidenceClass", "source"],
      "properties": {
        "from": { "type": "string", "minLength": 1 },
        "to": { "type": "string", "minLength": 1 },
        "fromLayer": { "type": "string", "minLength": 1 },
        "toLayer": { "type": "string", "minLength": 1 },
        "evidenceClass": { "$ref": "#/$defs/evidenceClass" },
        "source": { "type": "string", "minLength": 1 }
      }
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "status", "evidenceClass"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "kind": {
          "type": "string",
          "enum": [
            "unit-test",
            "acceptance-test",
            "property-test",
            "mutation-test",
            "coverage",
            "code-quality",
            "dependency-scan",
            "ui-qa",
            "performance",
            "real-database",
            "concurrency",
            "failure-injection",
            "constraint-approval",
            "other"
          ]
        },
        "status": {
          "type": "string",
          "enum": ["available", "missing", "failed"]
        },
        "evidenceClass": { "$ref": "#/$defs/evidenceClass" },
        "details": { "type": "string" },
        "source": { "type": "string", "minLength": 1 },
        "covers": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1 }
        },
        "provenance": { "$ref": "#/$defs/provenance" },
        "artifact": { "$ref": "#/$defs/artifact" }
      }
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": ["tool", "command", "actor", "role", "repositoryCommit", "observedAt"],
      "properties": {
        "tool": { "type": "string", "minLength": 1 },
        "version": { "type": "string", "minLength": 1 },
        "command": { "type": "string", "minLength": 1 },
        "actor": { "type": "string", "minLength": 1 },
        "role": {
          "type": "string",
          "enum": ["producer", "verifier", "reviewer", "ci"]
        },
        "repositoryCommit": { "type": "string", "minLength": 1 },
        "observedAt": { "type": "string", "format": "date-time" },
        "environment": { "type": "string", "minLength": 1 }
      }
    },
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "sha256"],
      "properties": {
        "path": { "type": "string", "minLength": 1 },
        "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
      }
    },
    "constraint": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "kind", "digest", "source"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "kind": {
          "type": "string",
          "enum": [
            "specification",
            "acceptance-test",
            "unit-test",
            "quality-profile",
            "qa-procedure",
            "other"
          ]
        },
        "digest": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "source": { "type": "string", "minLength": 1 },
        "location": { "type": "string", "minLength": 1 },
        "producer": { "type": "string", "minLength": 1 },
        "references": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1 }
        }
      }
    },
    "analyzerState": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "required", "status"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "required": { "type": "boolean" },
        "status": {
          "type": "string",
          "enum": ["pass", "failed"]
        },
        "error": { "type": "string" }
      }
    }
  }
}
