{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://fullsend.ai/normative/entity-context-snapshot/v1/check.schema.json",
  "title": "CheckMetadata",
  "type": "object",
  "required": ["id", "name", "status", "created_at", "head_sha"],
  "properties": {
    "id": { "$ref": "common.schema.json#/$defs/structural_id" },
    "name": { "type": "string", "minLength": 1 },
    "status": { "enum": ["queued", "in_progress", "completed"] },
    "conclusion": { "enum": ["success", "failure", "neutral", "cancelled", "skipped", "timed_out", "action_required", "stale"] },
    "created_at": { "$ref": "common.schema.json#/$defs/timestamp" },
    "head_sha": {
      "$ref": "common.schema.json#/$defs/git_oid",
      "description": "The target change-proposal HEAD SHA observed at collection time; only checks for that exact SHA are retained."
    },
    "started_at": { "$ref": "common.schema.json#/$defs/timestamp" },
    "never_started": {
      "type": "boolean",
      "description": "Required for completed checks. True only when the forge explicitly reports a never-started terminal, including a completed skipped or cancelled outcome with no native started_at under the adapter mapping; false requires started_at."
    },
    "completed_at": {
      "$ref": "common.schema.json#/$defs/timestamp",
      "description": "Native terminal timestamp when available. For never_started true, an absent native terminal timestamp is canonically represented by the source created_at value; this is not a runner-observed completion time."
    }
  },
  "allOf": [
    {
      "if": { "properties": { "status": { "const": "queued" } }, "required": ["status"] },
      "then": { "not": { "anyOf": [{ "required": ["started_at"] }, { "required": ["completed_at"] }, { "required": ["conclusion"] }, { "required": ["never_started"] }] } }
    },
    {
      "if": { "properties": { "status": { "const": "in_progress" } }, "required": ["status"] },
      "then": {
        "required": ["started_at"],
        "not": { "anyOf": [{ "required": ["completed_at"] }, { "required": ["conclusion"] }, { "required": ["never_started"] }] }
      }
    },
    {
      "if": { "properties": { "status": { "const": "completed" } }, "required": ["status"] },
      "then": {
        "required": ["completed_at", "conclusion", "never_started"],
        "if": { "properties": { "never_started": { "const": true } }, "required": ["never_started"] },
        "then": {
          "properties": { "conclusion": { "enum": ["cancelled", "skipped", "failure"] } },
          "not": { "required": ["started_at"] }
        },
        "else": { "required": ["started_at"] }
      }
    }
  ],
  "additionalProperties": false
}
