{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raccoonflow.ai/evidence-resolution.schema.json",
  "title": "Raccoon Flow Evidence Resolution Schema",
  "description": "Public data contract for resolving an evidence request into submitted evidence, review outcome, scorecard impact, and rating-history impact.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "resolutionId",
    "requestId",
    "status",
    "openedAt",
    "updatedAt",
    "actor",
    "subject",
    "submittedEvidence",
    "review",
    "scorecardImpact",
    "ratingHistoryImpact",
    "nextActions"
  ],
  "properties": {
    "schema": {
      "const": "raccoonflow.evidence-resolution.v0.1"
    },
    "resolutionId": {
      "type": "string",
      "pattern": "^rferes_[a-z0-9_]+$"
    },
    "requestId": {
      "type": "string",
      "pattern": "^rfer_[a-z0-9_]+$"
    },
    "status": {
      "type": "string",
      "enum": [
        "Open Request",
        "Evidence Submitted",
        "Under Review",
        "Verified",
        "Rejected",
        "Scorecard Updated",
        "Rating History Appended",
        "Closed"
      ]
    },
    "openedAt": {
      "type": "string",
      "format": "date-time"
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "closedAt": {
      "type": ["string", "null"],
      "format": "date-time"
    },
    "actor": {
      "type": "object",
      "additionalProperties": false,
      "required": ["role", "name"],
      "properties": {
        "role": { "type": "string" },
        "name": { "type": "string" },
        "ownerId": { "type": "string" },
        "profileUrl": { "type": "string", "format": "uri" }
      }
    },
    "subject": {
      "type": "object",
      "additionalProperties": false,
      "required": ["profileId", "vaultName", "profileJson", "scorecardUrl"],
      "properties": {
        "profileId": { "type": "string" },
        "vaultName": { "type": "string" },
        "profileJson": { "type": "string", "format": "uri" },
        "scorecardUrl": { "type": "string", "format": "uri" }
      }
    },
    "submittedEvidence": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["evidenceId", "type", "status", "evidenceUrl"],
        "properties": {
          "evidenceId": { "type": "string" },
          "type": { "type": "string" },
          "status": { "type": "string" },
          "evidenceUrl": { "type": "string", "format": "uri" },
          "submittedAt": { "type": "string", "format": "date-time" },
          "notes": { "type": "string" }
        }
      }
    },
    "review": {
      "type": "object",
      "additionalProperties": false,
      "required": ["state", "reviewUrl", "checks"],
      "properties": {
        "state": { "type": "string" },
        "reviewUrl": { "type": ["string", "null"], "format": "uri" },
        "checks": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["name", "result"],
            "properties": {
              "name": { "type": "string" },
              "result": { "type": "string" },
              "notes": { "type": "string" }
            }
          }
        }
      }
    },
    "scorecardImpact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["currentScorecardUrl", "affectedDimensions", "confidenceBefore", "confidenceAfter", "capsChanged"],
      "properties": {
        "currentScorecardUrl": { "type": "string", "format": "uri" },
        "affectedDimensions": {
          "type": "array",
          "items": { "type": "string" }
        },
        "confidenceBefore": { "type": "string" },
        "confidenceAfter": { "type": "string" },
        "capsChanged": {
          "type": "array",
          "items": { "type": "string" }
        },
        "scoreDelta": { "type": "integer" },
        "notes": { "type": "string" }
      }
    },
    "ratingHistoryImpact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["shouldAppend", "changeType", "historyUrl"],
      "properties": {
        "shouldAppend": { "type": "boolean" },
        "changeType": { "type": "string" },
        "historyUrl": { "type": "string", "format": "uri" },
        "pendingChangeId": { "type": ["string", "null"] }
      }
    },
    "nextActions": {
      "type": "array",
      "items": { "type": "string" }
    }
  }
}
