{
  "$defs": {
    "FlagKind": {
      "description": "Flag kind.",
      "oneOf": [
        {
          "const": "release",
          "description": "Gate a new feature behind a flag during rollout.",
          "type": "string"
        },
        {
          "const": "experiment",
          "description": "A/B / multi-variate experiment.",
          "type": "string"
        },
        {
          "const": "ops",
          "description": "Operational toggle (load shedding, circuit breaker).",
          "type": "string"
        },
        {
          "const": "permission",
          "description": "Permission / entitlement-gating (per plan tier).",
          "type": "string"
        },
        {
          "const": "kill_switch",
          "description": "Kill switch (cut traffic / disable behaviour on incident).",
          "type": "string"
        },
        {
          "const": "cohort",
          "description": "Cohort-targeting (e.g. early-access programme).",
          "type": "string"
        }
      ]
    },
    "FlagState": {
      "description": "Flag state.",
      "oneOf": [
        {
          "const": "off",
          "description": "Disabled — flag returns default value.",
          "type": "string"
        },
        {
          "const": "on",
          "description": "Fully on for everyone.",
          "type": "string"
        },
        {
          "const": "partial",
          "description": "Partial rollout via targeting rules.",
          "type": "string"
        },
        {
          "const": "removed",
          "description": "Flag removed from registry (kept for audit).",
          "type": "string"
        }
      ]
    },
    "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"
    },
    "TargetingRule": {
      "description": "Targeting rule (free-form for portability).",
      "properties": {
        "condition": {
          "description": "Match condition (free-form: vendor SDK specific syntax).",
          "type": "string"
        },
        "label": {
          "description": "Rule label (e.g. \"internal_tenants\", \"early_access_cohort\").",
          "type": "string"
        },
        "on_treatment": {
          "description": "Whether matched entities receive the on-treatment.",
          "type": "boolean"
        },
        "rollout_pct": {
          "description": "Rollout pct for matched entities (0-100).",
          "format": "double",
          "type": [
            "number",
            "null"
          ]
        }
      },
      "required": [
        "label",
        "condition",
        "on_treatment"
      ],
      "type": "object"
    }
  },
  "$id": "https://corpospec.com/schemas/v0.16.0/feature-flag.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "One feature flag.",
  "properties": {
    "created_at": {
      "$ref": "#/$defs/IsoDate"
    },
    "decision_ref": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "PathRef to the BDR / experiment design / runbook."
    },
    "description": {
      "type": "string"
    },
    "entity": {
      "$ref": "#/$defs/PathRef"
    },
    "expires_at": {
      "anyOf": [
        {
          "$ref": "#/$defs/IsoDate"
        },
        {
          "type": "null"
        }
      ],
      "description": "Date the flag should be removed (mandatory for Release +\nExperiment kinds)."
    },
    "id": {
      "$ref": "#/$defs/PathRef"
    },
    "key": {
      "description": "Stable flag-key used in code (snake_case).",
      "type": "string"
    },
    "kind": {
      "$ref": "#/$defs/FlagKind"
    },
    "max_age_warning_days": {
      "description": "Max-age days before warning fires (governance hygiene).",
      "format": "int32",
      "type": "integer"
    },
    "owner": {
      "$ref": "#/$defs/PathRef"
    },
    "platform": {
      "description": "Vendor / platform (e.g. \"growthbook\", \"launchdarkly\",\n\"statsig\", \"self-hosted\").",
      "type": "string"
    },
    "product": {
      "$ref": "#/$defs/PathRef",
      "description": "PathRef to product / service."
    },
    "rollout_pct": {
      "description": "Overall rollout pct (when state == Partial).",
      "format": "double",
      "type": [
        "number",
        "null"
      ]
    },
    "state": {
      "$ref": "#/$defs/FlagState"
    },
    "targeting_rules": {
      "items": {
        "$ref": "#/$defs/TargetingRule"
      },
      "type": "array"
    }
  },
  "required": [
    "id",
    "entity",
    "key",
    "kind",
    "state",
    "description",
    "product",
    "targeting_rules",
    "owner",
    "created_at",
    "max_age_warning_days",
    "platform"
  ],
  "title": "FeatureFlagRecord",
  "type": "object",
  "x-corpospec-pillar": "operations"
}