{
  "$defs": {
    "ExperimentDecision": {
      "description": "Decision outcome.",
      "oneOf": [
        {
          "const": "ship_treatment",
          "description": "Ship the treatment variant.",
          "type": "string"
        },
        {
          "const": "ship_control",
          "description": "Ship the control (i.e. abandon the treatment).",
          "type": "string"
        },
        {
          "const": "inconclusive",
          "description": "Inconclusive — keep control, may re-run.",
          "type": "string"
        },
        {
          "const": "negative_ship_control",
          "description": "Negative — treatment is harmful, roll back immediately.",
          "type": "string"
        },
        {
          "const": "pending",
          "description": "Pending decision.",
          "type": "string"
        }
      ]
    },
    "ExperimentMetric": {
      "description": "One metric attached to the experiment.",
      "properties": {
        "ci_lower_pct": {
          "description": "95% CI lower bound.",
          "format": "double",
          "type": [
            "number",
            "null"
          ]
        },
        "ci_upper_pct": {
          "description": "95% CI upper bound.",
          "format": "double",
          "type": [
            "number",
            "null"
          ]
        },
        "direction": {
          "$ref": "#/$defs/ExperimentMetricDirection"
        },
        "guardrail": {
          "description": "Whether this is a guardrail (must not regress).",
          "type": "boolean"
        },
        "key": {
          "description": "KPI / metric key (typically a kpi_definition.key).",
          "type": "string"
        },
        "minimum_detectable_effect_pct": {
          "description": "Minimum-detectable-effect (pct) — input to power analysis.",
          "format": "double",
          "type": "number"
        },
        "observed_lift_pct": {
          "description": "Observed lift (None until concluded).",
          "format": "double",
          "type": [
            "number",
            "null"
          ]
        },
        "p_value": {
          "description": "P-value of observed lift.",
          "format": "double",
          "type": [
            "number",
            "null"
          ]
        },
        "primary": {
          "description": "Whether this is the *primary* (decision-driving) metric.",
          "type": "boolean"
        }
      },
      "required": [
        "key",
        "primary",
        "guardrail",
        "direction",
        "minimum_detectable_effect_pct"
      ],
      "type": "object"
    },
    "ExperimentMetricDirection": {
      "description": "Metric direction (improvement criterion).",
      "oneOf": [
        {
          "const": "increase",
          "description": "Higher = better.",
          "type": "string"
        },
        {
          "const": "decrease",
          "description": "Lower = better.",
          "type": "string"
        },
        {
          "const": "track",
          "description": "Just track (guardrail — should not move).",
          "type": "string"
        }
      ]
    },
    "ExperimentStatus": {
      "description": "Lifecycle.",
      "oneOf": [
        {
          "const": "designed",
          "description": "Designed but not started.",
          "type": "string"
        },
        {
          "const": "pre_registered",
          "description": "Pre-registered (hypothesis + analysis plan committed).",
          "type": "string"
        },
        {
          "const": "running",
          "description": "In flight — collecting data.",
          "type": "string"
        },
        {
          "const": "stopped_early",
          "description": "Stopped early (e.g. clear win / clear loss / guardrail breach).",
          "type": "string"
        },
        {
          "const": "concluded",
          "description": "Concluded at scheduled end.",
          "type": "string"
        },
        {
          "const": "analysed",
          "description": "Analysed.",
          "type": "string"
        },
        {
          "const": "decided",
          "description": "Decision made + shipped (or rolled back).",
          "type": "string"
        },
        {
          "const": "archived",
          "description": "Archived.",
          "type": "string"
        }
      ]
    },
    "ExperimentVariant": {
      "description": "One experiment variant.",
      "properties": {
        "allocation_pct": {
          "description": "Allocation pct (sum across variants = 100).",
          "format": "double",
          "type": "number"
        },
        "description": {
          "type": "string"
        },
        "key": {
          "description": "Variant key (e.g. \"control\", \"treatment_a\", \"treatment_b\").",
          "type": "string"
        }
      },
      "required": [
        "key",
        "description",
        "allocation_pct"
      ],
      "type": "object"
    },
    "IsoDate": {
      "description": "ISO 8601 date (YYYY-MM-DD).",
      "format": "date",
      "type": "string"
    },
    "PathRef": {
      "description": "Path-based cross-reference relative to .corpospec/ root.\nPattern: `^[a-z0-9_-]+(/[a-z0-9_.-]+)+$`",
      "pattern": "^[a-z0-9_-]+(/[a-z0-9_.-]+)+$",
      "type": "string"
    }
  },
  "$id": "https://corpospec.com/schemas/v0.16.0/ab-experiment.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "A/B experiment record.",
  "properties": {
    "alpha": {
      "description": "Statistical-significance threshold (α).",
      "format": "double",
      "type": "number"
    },
    "analysis_plan": {
      "description": "Detailed analysis plan (pre-registered).",
      "type": "string"
    },
    "decision": {
      "$ref": "#/$defs/ExperimentDecision"
    },
    "decision_ref": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "PathRef to the decision narrative (BDR / readout)."
    },
    "end_date": {
      "$ref": "#/$defs/IsoDate"
    },
    "entity": {
      "$ref": "#/$defs/PathRef"
    },
    "feature_flag_ref": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "PathRef to the feature flag implementing the variants."
    },
    "hypothesis": {
      "description": "One-sentence hypothesis (\"If we do X, then Y will move by Z\").",
      "type": "string"
    },
    "id": {
      "$ref": "#/$defs/PathRef"
    },
    "metrics": {
      "items": {
        "$ref": "#/$defs/ExperimentMetric"
      },
      "type": "array"
    },
    "name": {
      "type": "string"
    },
    "observed_sample_size_per_variant": {
      "description": "Observed sample size per variant at end.",
      "format": "int64",
      "type": [
        "integer",
        "null"
      ]
    },
    "owner": {
      "$ref": "#/$defs/PathRef"
    },
    "power": {
      "description": "Statistical-power threshold (1−β).",
      "format": "double",
      "type": "number"
    },
    "start_date": {
      "$ref": "#/$defs/IsoDate"
    },
    "status": {
      "$ref": "#/$defs/ExperimentStatus"
    },
    "target_sample_size_per_variant": {
      "description": "Target sample size per variant (from power analysis).",
      "format": "int64",
      "type": "integer"
    },
    "variants": {
      "items": {
        "$ref": "#/$defs/ExperimentVariant"
      },
      "type": "array"
    }
  },
  "required": [
    "id",
    "entity",
    "status",
    "name",
    "hypothesis",
    "analysis_plan",
    "variants",
    "metrics",
    "target_sample_size_per_variant",
    "alpha",
    "power",
    "start_date",
    "end_date",
    "owner",
    "decision"
  ],
  "title": "AbExperiment",
  "type": "object",
  "x-corpospec-pillar": "operations"
}