{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openalpha-dev.github.io/alphaspec/schema/0.1/gate-result.schema.json",
  "title": "AlphaSpec Gate Result",
  "description": "What a runtime returns after judging a submitted artifact or score series. Produced by the runtime, never by the submitter.",
  "type": "object",
  "required": ["contractVersion", "kind", "passed", "computedBy", "checks"],
  "additionalProperties": false,
  "properties": {
    "contractVersion": { "$ref": "common.schema.json#/$defs/contractVersion" },
    "kind": { "const": "gate-result" },
    "subject": { "type": "string", "description": "Identifier of the judged artifact or score series." },
    "passed": { "type": "boolean" },
    "computedBy": {
      "enum": ["PLATFORM", "SELF_REPORTED"],
      "description": "PLATFORM: performance figures were recomputed by the runtime. SELF_REPORTED: they came from the submitter. Public rankings must accept PLATFORM only."
    },
    "sample": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "inSampleFrom": { "type": "string", "format": "date" },
        "inSampleTo": { "type": "string", "format": "date" },
        "outOfSampleFrom": { "type": "string", "format": "date", "description": "Chosen by the runtime and not visible at submission time." },
        "outOfSampleTo": { "type": "string", "format": "date" }
      }
    },
    "checks": {
      "type": "array",
      "description": "One entry per criterion, so a failure can be diffed and explained, not just reported.",
      "items": {
        "type": "object",
        "required": ["code", "passed"],
        "additionalProperties": false,
        "properties": {
          "code": {
            "enum": [
              "GATE_MIN_RETURN", "GATE_MAX_DRAWDOWN", "GATE_MIN_SHARPE",
              "GATE_OUT_OF_SAMPLE", "GATE_MULTIPLE_TESTING", "GATE_LOOKAHEAD",
              "GATE_COST_SENSITIVITY", "GATE_CAPACITY", "GATE_MARKETABILITY"
            ]
          },
          "metric": {
            "type": "string",
            "description": "What `actual` and `threshold` measure, so a reader never infers it from the code. One check can switch measures (out-of-sample is judged on excess return when the runtime has a benchmark index, on Sharpe when it has not). Values used by the reference runtime: totalReturn, maxDrawdown, sharpe, excessReturnVsIndex, deflatedSharpeProbability, structural. Returns and drawdowns are fractions (0.05 = 5%)."
          },
          "passed": { "type": "boolean" },
          "actual": { "type": ["number", "string", "null"] },
          "threshold": { "type": ["number", "string", "null"] },
          "hint": { "type": "string", "description": "What to change to pass, in plain language." }
        }
      }
    }
  }
}
