{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "YearEndCloseReadinessOutput",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "service",
    "service_version",
    "evaluated_at_utc",
    "evidence_mode",
    "source_fresh_for_current_use",
    "period",
    "policy_id",
    "policy_version",
    "policy_sha256",
    "request_sha256",
    "overall_status",
    "counts",
    "checks",
    "missing_evidence",
    "overdue_reconciliations",
    "unresolved_exception_counts",
    "blocked_prerequisites",
    "unmet_check_ids",
    "source_evidence",
    "limitations",
    "scope",
    "fee_eligibility"
  ],
  "properties": {
    "service": {
      "const": "year-end-close-readiness"
    },
    "service_version": {
      "const": "year-end-close-readiness-1.0.0"
    },
    "evaluated_at_utc": {
      "type": "string"
    },
    "evidence_mode": {
      "type": "string",
      "enum": [
        "current",
        "snapshot_replay"
      ]
    },
    "source_fresh_for_current_use": {
      "type": "boolean"
    },
    "period": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "start",
        "end",
        "basis"
      ],
      "properties": {
        "start": {
          "type": "string",
          "format": "date"
        },
        "end": {
          "type": "string",
          "format": "date"
        },
        "basis": {
          "type": "string",
          "enum": [
            "cash",
            "accrual"
          ]
        }
      }
    },
    "policy_id": {
      "type": "string"
    },
    "policy_version": {
      "type": "string"
    },
    "policy_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "request_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "overall_status": {
      "type": "string",
      "enum": [
        "READY",
        "NOT_READY",
        "REVIEW",
        "UNKNOWN"
      ]
    },
    "counts": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "PASS",
        "FAIL",
        "REVIEW",
        "UNKNOWN"
      ],
      "properties": {
        "PASS": {
          "type": "integer",
          "minimum": 0
        },
        "FAIL": {
          "type": "integer",
          "minimum": 0
        },
        "REVIEW": {
          "type": "integer",
          "minimum": 0
        },
        "UNKNOWN": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "checks": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "check_id",
          "status",
          "reason",
          "predicate",
          "mode",
          "fact_refs",
          "account_refs",
          "prerequisite_refs",
          "cutoff",
          "evidence_refs"
        ],
        "properties": {
          "check_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "PASS",
              "FAIL",
              "REVIEW",
              "UNKNOWN"
            ]
          },
          "reason": {
            "type": "string"
          },
          "predicate": {
            "type": "string"
          },
          "mode": {
            "type": "string",
            "enum": [
              "required",
              "review"
            ]
          },
          "fact_refs": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "account_refs": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "prerequisite_refs": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "cutoff": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "evidence_refs": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      }
    },
    "missing_evidence": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "overdue_reconciliations": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "unresolved_exception_counts": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "blocked_prerequisites": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "unmet_check_ids": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "source_evidence": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "limitations": {
      "type": "array",
      "minItems": 8,
      "items": {
        "type": "string"
      }
    },
    "scope": {
      "const": "PUBLIC_PRODUCTION_SNAPSHOT"
    },
    "fee_eligibility": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "eligible",
        "price_atomic",
        "currency",
        "rule",
        "unknown_no_charge",
        "settlement_claimed"
      ],
      "properties": {
        "eligible": {
          "type": "boolean"
        },
        "price_atomic": {
          "const": "50000"
        },
        "currency": {
          "const": "USDC"
        },
        "rule": {
          "const": "READY_NOT_READY_REVIEW_IF_NO_UNKNOWN_AND_VALIDATED"
        },
        "unknown_no_charge": {
          "const": true
        },
        "settlement_claimed": {
          "const": false
        }
      }
    }
  }
}
