{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tenantpilot.local/contracts/tenant-coverage-truth.schema.json",
  "title": "Tenant Coverage Truth",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "tenantId",
    "hasCurrentCoverageResult",
    "summary",
    "rows"
  ],
  "properties": {
    "tenantId": {
      "type": "integer"
    },
    "basisRun": {
      "oneOf": [
        {
          "$ref": "#/$defs/basisRun"
        },
        {
          "type": "null"
        }
      ]
    },
    "hasCurrentCoverageResult": {
      "type": "boolean"
    },
    "summary": {
      "$ref": "#/$defs/summary"
    },
    "rows": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/row"
      }
    }
  },
  "$defs": {
    "basisRun": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "outcome",
        "completedAt"
      ],
      "properties": {
        "id": {
          "type": "integer"
        },
        "outcome": {
          "type": "string",
          "enum": [
            "succeeded",
            "partially_succeeded",
            "failed",
            "blocked"
          ]
        },
        "completedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "summary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "supportedTypes",
        "succeededTypes",
        "failedTypes",
        "skippedTypes",
        "unknownTypes",
        "followUpTypes",
        "observedItems"
      ],
      "properties": {
        "supportedTypes": {
          "type": "integer",
          "minimum": 0
        },
        "succeededTypes": {
          "type": "integer",
          "minimum": 0
        },
        "failedTypes": {
          "type": "integer",
          "minimum": 0
        },
        "skippedTypes": {
          "type": "integer",
          "minimum": 0
        },
        "unknownTypes": {
          "type": "integer",
          "minimum": 0
        },
        "followUpTypes": {
          "type": "integer",
          "minimum": 0
        },
        "observedItems": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "row": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "segment",
        "label",
        "category",
        "coverageState",
        "followUpRequired",
        "observedItemCount",
        "supportsDependencies"
      ],
      "properties": {
        "type": {
          "type": "string"
        },
        "segment": {
          "type": "string",
          "enum": [
            "policy",
            "foundation"
          ]
        },
        "label": {
          "type": "string"
        },
        "category": {
          "type": "string"
        },
        "platform": {
          "type": [
            "string",
            "null"
          ]
        },
        "coverageState": {
          "type": "string",
          "enum": [
            "succeeded",
            "failed",
            "skipped",
            "unknown"
          ]
        },
        "followUpRequired": {
          "type": "boolean"
        },
        "observedItemCount": {
          "type": "integer",
          "minimum": 0
        },
        "basisErrorCode": {
          "type": [
            "string",
            "null"
          ]
        },
        "restoreMode": {
          "type": [
            "string",
            "null"
          ]
        },
        "riskLevel": {
          "type": [
            "string",
            "null"
          ]
        },
        "supportsDependencies": {
          "type": "boolean"
        }
      }
    }
  }
}
