{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tenantatlas.local/schemas/heavy-governance-hotspot-inventory.schema.json",
  "title": "HeavyGovernanceHotspotInventory",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "artifactDirectory",
    "budgetContract",
    "hotspotInventory",
    "decompositionRecords",
    "slimmingDecisions",
    "budgetSnapshots",
    "budgetOutcome",
    "authorGuidance"
  ],
  "properties": {
    "version": {
      "type": "integer",
      "minimum": 1
    },
    "artifactDirectory": {
      "type": "string",
      "const": "storage/logs/test-lanes"
    },
    "budgetContract": {
      "$ref": "#/$defs/budgetContract"
    },
    "hotspotInventory": {
      "type": "array",
      "minItems": 5,
      "items": {
        "$ref": "#/$defs/hotspotInventoryRecord"
      },
      "allOf": [
        {
          "contains": {
            "type": "object",
            "required": ["familyId"],
            "properties": {
              "familyId": {
                "const": "baseline-profile-start-surfaces"
              }
            }
          }
        },
        {
          "contains": {
            "type": "object",
            "required": ["familyId"],
            "properties": {
              "familyId": {
                "const": "findings-workflow-surfaces"
              }
            }
          }
        },
        {
          "contains": {
            "type": "object",
            "required": ["familyId"],
            "properties": {
              "familyId": {
                "const": "finding-bulk-actions-workflow"
              }
            }
          }
        }
      ]
    },
    "decompositionRecords": {
      "type": "array",
      "minItems": 3,
      "items": {
        "$ref": "#/$defs/decompositionRecord"
      }
    },
    "slimmingDecisions": {
      "type": "array",
      "minItems": 3,
      "items": {
        "$ref": "#/$defs/slimmingDecision"
      }
    },
    "budgetSnapshots": {
      "type": "array",
      "minItems": 2,
      "items": {
        "$ref": "#/$defs/budgetSnapshot"
      }
    },
    "budgetOutcome": {
      "$ref": "#/$defs/budgetOutcome"
    },
    "authorGuidance": {
      "type": "array",
      "minItems": 4,
      "items": {
        "$ref": "#/$defs/authorGuidanceRule"
      }
    }
  },
  "$defs": {
    "classificationId": {
      "type": "string",
      "enum": [
        "ui-workflow",
        "surface-guard",
        "discovery-heavy"
      ]
    },
    "costDriverCategory": {
      "type": "string",
      "enum": [
        "overbroad",
        "redundant",
        "discovery-heavy",
        "workflow-heavy",
        "surface-heavy",
        "helper-driven",
        "fixture-driven",
        "intentionally-heavy"
      ]
    },
    "budgetDecisionStatus": {
      "type": "string",
      "enum": [
        "pending",
        "recovered",
        "recalibrated"
      ]
    },
    "hotspotStatus": {
      "type": "string",
      "enum": [
        "seeded",
        "decomposed",
        "slimmed",
        "retained",
        "follow-up"
      ]
    },
    "priorityTier": {
      "type": "string",
      "enum": [
        "primary",
        "secondary",
        "residual"
      ]
    },
    "residualCostSource": {
      "type": "string",
      "enum": [
        "family-breadth",
        "helper-driven",
        "fixture-driven",
        "mixed",
        "intentional-depth"
      ]
    },
    "recommendedAction": {
      "type": "string",
      "enum": [
        "split-family",
        "centralize-work",
        "narrow-assertions",
        "retain-as-heavy",
        "route-follow-up"
      ]
    },
    "slimmingDecisionType": {
      "type": "string",
      "enum": [
        "split",
        "centralize",
        "trim-duplicate-work",
        "retain",
        "follow-up"
      ]
    },
    "budgetStatus": {
      "type": "string",
      "enum": [
        "within-budget",
        "warning",
        "over-budget"
      ]
    },
    "budgetContract": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "laneId",
        "summaryThresholdSeconds",
        "evaluationThresholdSeconds",
        "normalizedThresholdSeconds",
        "baselineSource",
        "enforcementLevel",
        "lifecycleState",
        "decisionStatus"
      ],
      "properties": {
        "laneId": {
          "type": "string",
          "const": "heavy-governance"
        },
        "summaryThresholdSeconds": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "evaluationThresholdSeconds": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "normalizedThresholdSeconds": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "baselineSource": {
          "type": "string"
        },
        "enforcementLevel": {
          "type": "string",
          "enum": ["report-only", "warn", "hard-fail"]
        },
        "lifecycleState": {
          "type": "string",
          "enum": ["draft", "documented", "recalibrated"]
        },
        "reconciliationRationale": {
          "type": "string"
        },
        "decisionStatus": {
          "$ref": "#/$defs/budgetDecisionStatus"
        }
      }
    },
    "hotspotInventoryRecord": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "familyId",
        "classificationId",
        "purpose",
        "measuredSeconds",
        "hotspotFiles",
        "costDriverCategory",
        "priorityTier",
        "status"
      ],
      "properties": {
        "familyId": {
          "type": "string",
          "minLength": 1
        },
        "classificationId": {
          "$ref": "#/$defs/classificationId"
        },
        "purpose": {
          "type": "string",
          "minLength": 1
        },
        "measuredSeconds": {
          "type": "number",
          "minimum": 0
        },
        "hotspotFiles": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "costDriverCategory": {
          "$ref": "#/$defs/costDriverCategory"
        },
        "priorityTier": {
          "$ref": "#/$defs/priorityTier"
        },
        "currentBudgetSeconds": {
          "type": "number",
          "minimum": 0
        },
        "status": {
          "$ref": "#/$defs/hotspotStatus"
        }
      }
    },
    "decompositionRecord": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "familyId",
        "trustType",
        "requiredBreadth",
        "duplicateWorkSources",
        "residualCostSource",
        "recommendedAction",
        "notes"
      ],
      "properties": {
        "familyId": {
          "type": "string"
        },
        "trustType": {
          "type": "string",
          "enum": ["workflow-trust", "surface-trust", "guard-trust", "discovery-trust"]
        },
        "requiredBreadth": {
          "type": "string",
          "minLength": 1
        },
        "duplicateWorkSources": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "duplicateWorkEstimateSeconds": {
          "type": "number",
          "minimum": 0
        },
        "residualCostSource": {
          "$ref": "#/$defs/residualCostSource"
        },
        "recommendedAction": {
          "$ref": "#/$defs/recommendedAction"
        },
        "notes": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "slimmingDecision": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "familyId",
        "decisionType",
        "guardPreservationPlan",
        "owner",
        "validationPlan"
      ],
      "properties": {
        "familyId": {
          "type": "string"
        },
        "decisionType": {
          "$ref": "#/$defs/slimmingDecisionType"
        },
        "scope": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "guardPreservationPlan": {
          "type": "string",
          "minLength": 1
        },
        "expectedDeltaSeconds": {
          "type": "number"
        },
        "owner": {
          "type": "string",
          "minLength": 1
        },
        "validationPlan": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        }
      }
    },
    "budgetSnapshot": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "snapshotId",
        "capturedAt",
        "wallClockSeconds",
        "classificationTotals",
        "familyTotals",
        "slowestEntries",
        "artifactPaths",
        "budgetStatus"
      ],
      "properties": {
        "snapshotId": {
          "type": "string",
          "minLength": 1
        },
        "capturedAt": {
          "type": "string",
          "format": "date-time"
        },
        "wallClockSeconds": {
          "type": "number",
          "minimum": 0
        },
        "classificationTotals": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["classificationId", "totalWallClockSeconds"],
            "properties": {
              "classificationId": {
                "$ref": "#/$defs/classificationId"
              },
              "totalWallClockSeconds": {
                "type": "number",
                "minimum": 0
              }
            }
          }
        },
        "familyTotals": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["familyId", "totalWallClockSeconds"],
            "properties": {
              "familyId": {
                "type": "string"
              },
              "totalWallClockSeconds": {
                "type": "number",
                "minimum": 0
              }
            }
          }
        },
        "slowestEntries": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["label", "wallClockSeconds"],
            "properties": {
              "label": {
                "type": "string"
              },
              "wallClockSeconds": {
                "type": "number",
                "minimum": 0
              }
            }
          }
        },
        "artifactPaths": {
          "type": "object",
          "additionalProperties": false,
          "required": ["summary", "budget", "report"],
          "properties": {
            "summary": {
              "type": "string",
              "pattern": "^storage/logs/test-lanes/"
            },
            "budget": {
              "type": "string",
              "pattern": "^storage/logs/test-lanes/"
            },
            "report": {
              "type": "string",
              "pattern": "^storage/logs/test-lanes/"
            }
          }
        },
        "budgetStatus": {
          "$ref": "#/$defs/budgetStatus"
        }
      }
    },
    "budgetOutcome": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "outcomeId",
        "decisionStatus",
        "finalThresholdSeconds",
        "finalMeasuredSeconds",
        "deltaSeconds",
        "deltaPercent",
        "remainingOpenFamilies",
        "justification"
      ],
      "properties": {
        "outcomeId": {
          "type": "string",
          "minLength": 1
        },
        "decisionStatus": {
          "$ref": "#/$defs/budgetDecisionStatus"
        },
        "finalThresholdSeconds": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "finalMeasuredSeconds": {
          "type": "number",
          "minimum": 0
        },
        "deltaSeconds": {
          "type": "number"
        },
        "deltaPercent": {
          "type": "number"
        },
        "remainingOpenFamilies": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "justification": {
          "type": "string",
          "minLength": 1
        },
        "followUpDebt": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "authorGuidanceRule": {
      "type": "object",
      "additionalProperties": false,
      "required": ["ruleId", "whenToUse", "requiredDecision", "antiPattern", "preferredOutcome"],
      "properties": {
        "ruleId": {
          "type": "string",
          "minLength": 1
        },
        "whenToUse": {
          "type": "string",
          "minLength": 1
        },
        "requiredDecision": {
          "type": "string",
          "minLength": 1
        },
        "antiPattern": {
          "type": "string",
          "minLength": 1
        },
        "preferredOutcome": {
          "type": "string",
          "minLength": 1
        }
      }
    }
  }
}