{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://submuxhq.github.io/CodeDecay/schemas/product-failure-bundle.schema.json",
  "title": "CodeDecay Product Failure Bundle",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "id",
    "checkId",
    "checkKind",
    "priority",
    "target",
    "title",
    "summary",
    "classification",
    "failedStep",
    "neighboringSteps",
    "artifacts",
    "expected",
    "actual",
    "impactedFiles",
    "suggestedFixTasks",
    "rerunCommand"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "id": {
      "type": "string",
      "minLength": 1
    },
    "checkId": {
      "type": "string",
      "minLength": 1
    },
    "checkKind": {
      "enum": ["ui", "api", "workflow"]
    },
    "priority": {
      "enum": ["low", "medium", "high"]
    },
    "target": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id"],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "environment": {
          "type": "string",
          "minLength": 1
        },
        "baseUrl": {
          "type": "string",
          "format": "uri"
        }
      }
    },
    "title": {
      "type": "string",
      "minLength": 1
    },
    "summary": {
      "type": "string",
      "minLength": 1
    },
    "classification": {
      "enum": [
        "confirmed-regression",
        "likely-flaky",
        "environment-failure",
        "auth-or-test-data-failure",
        "generated-test-weakness",
        "unknown"
      ]
    },
    "classificationConfidence": {
      "type": "number",
      "minimum": 0,
      "maximum": 1
    },
    "classificationEvidence": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "failedStep": {
      "$ref": "#/$defs/step"
    },
    "neighboringSteps": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/step"
      }
    },
    "artifacts": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/artifact"
      }
    },
    "expected": {
      "type": "string",
      "minLength": 1
    },
    "actual": {
      "type": "string",
      "minLength": 1
    },
    "impactedFiles": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "rootCauseHypothesis": {
      "type": "string",
      "minLength": 1
    },
    "suggestedFixTasks": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "rerunCommand": {
      "type": "string",
      "minLength": 1
    }
  },
  "$defs": {
    "step": {
      "type": "object",
      "additionalProperties": false,
      "required": ["index", "label", "status"],
      "properties": {
        "index": {
          "type": "integer",
          "minimum": 0
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "enum": ["passed", "failed", "skipped"]
        },
        "expected": {
          "type": "string",
          "minLength": 1
        },
        "actual": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind"],
      "properties": {
        "kind": {
          "enum": [
            "screenshot",
            "trace",
            "video",
            "dom-snapshot",
            "console-log",
            "network-log",
            "test-source",
            "request-response-diff",
            "other"
          ]
        },
        "path": {
          "type": "string",
          "minLength": 1
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string",
          "minLength": 1
        }
      }
    }
  }
}
