{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://cre-acquisition-orchestrator.local/schemas/events/phase-completion.schema.json",
  "title": "Phase Completion Event",
  "type": "object",
  "required": [
    "type",
    "dealId",
    "phase",
    "phaseId",
    "status",
    "verdict",
    "durationMs",
    "timestamp",
    "traceId"
  ],
  "properties": {
    "type": {
      "type": "string",
      "enum": [
        "PHASE_COMPLETION"
      ]
    },
    "dealId": {
      "type": "string",
      "minLength": 1
    },
    "phase": {
      "$ref": "../common/enums.schema.json#/$defs/phaseKey"
    },
    "phaseId": {
      "type": "string",
      "minLength": 1
    },
    "status": {
      "$ref": "../common/enums.schema.json#/$defs/status"
    },
    "verdict": {
      "$ref": "../common/enums.schema.json#/$defs/verdict"
    },
    "durationMs": {
      "type": "number",
      "minimum": 0
    },
    "dataGapCount": {
      "type": "number",
      "minimum": 0
    },
    "redFlagCount": {
      "type": "number",
      "minimum": 0
    },
    "criticalFlags": {
      "type": "array",
      "items": {
        "$ref": "../common/flag.schema.json"
      }
    },
    "metrics": {
      "type": "object",
      "required": [],
      "properties": {
        "riskScore": {
          "type": "number"
        },
        "redFlagCount": {
          "type": "number"
        },
        "dataGapCount": {
          "type": "number"
        }
      },
      "additionalProperties": false
    },
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "traceId": {
      "type": "string",
      "minLength": 1
    }
  },
  "additionalProperties": false
}
