{
  "$defs": {
    "IsoDate": {
      "description": "ISO 8601 date (YYYY-MM-DD).",
      "format": "date",
      "type": "string"
    },
    "KpiCadence": {
      "description": "Reporting cadence.",
      "enum": [
        "realtime",
        "daily",
        "weekly",
        "monthly",
        "quarterly",
        "annual"
      ],
      "type": "string"
    },
    "KpiDomain": {
      "description": "KPI domain.",
      "oneOf": [
        {
          "const": "revenue",
          "description": "Revenue / MRR / ARR / NRR / GRR / churn.",
          "type": "string"
        },
        {
          "const": "customer",
          "description": "Customer success / engagement.",
          "type": "string"
        },
        {
          "const": "product",
          "description": "Product usage / adoption.",
          "type": "string"
        },
        {
          "const": "engineering",
          "description": "Engineering velocity / quality.",
          "type": "string"
        },
        {
          "const": "people",
          "description": "People / workforce (ISO 30414).",
          "type": "string"
        },
        {
          "const": "marketing",
          "description": "Marketing / pipeline.",
          "type": "string"
        },
        {
          "const": "sales",
          "description": "Sales pipeline.",
          "type": "string"
        },
        {
          "const": "finance",
          "description": "Finance / unit economics.",
          "type": "string"
        },
        {
          "const": "operational",
          "description": "Operational performance / SLO.",
          "type": "string"
        },
        {
          "const": "risk",
          "description": "Risk / compliance.",
          "type": "string"
        },
        {
          "const": "sustainability",
          "description": "Sustainability (ESRS / IFRS S2).",
          "type": "string"
        }
      ]
    },
    "KpiPolarity": {
      "description": "Polarity — whether higher is better.",
      "oneOf": [
        {
          "const": "higher_is_better",
          "description": "Higher is better (e.g. MRR, NRR).",
          "type": "string"
        },
        {
          "const": "lower_is_better",
          "description": "Lower is better (e.g. churn, MTTR).",
          "type": "string"
        },
        {
          "const": "target_band",
          "description": "Target-band (e.g. headcount growth — not too fast, not too\nslow).",
          "type": "string"
        }
      ]
    },
    "KpiStatus": {
      "description": "Lifecycle.",
      "enum": [
        "proposed",
        "active",
        "deprecated",
        "retired"
      ],
      "type": "string"
    },
    "KpiThresholds": {
      "description": "Threshold bands (red / yellow / green).",
      "properties": {
        "green_threshold": {
          "description": "Above this value (HigherIsBetter) = green; below = at least\nyellow.",
          "format": "double",
          "type": "number"
        },
        "red_threshold": {
          "description": "Below this value (HigherIsBetter) = red.",
          "format": "double",
          "type": "number"
        }
      },
      "required": [
        "green_threshold",
        "red_threshold"
      ],
      "type": "object"
    },
    "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/kpi-definition.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "KPI definition.",
  "properties": {
    "cadence": {
      "$ref": "#/$defs/KpiCadence",
      "description": "Reporting cadence."
    },
    "data_source": {
      "$ref": "#/$defs/PathRef",
      "description": "PathRef to the underlying data source / query / dashboard."
    },
    "description": {
      "type": "string"
    },
    "domain": {
      "$ref": "#/$defs/KpiDomain"
    },
    "effective_from": {
      "$ref": "#/$defs/IsoDate"
    },
    "effective_to": {
      "anyOf": [
        {
          "$ref": "#/$defs/IsoDate"
        },
        {
          "type": "null"
        }
      ]
    },
    "entity": {
      "$ref": "#/$defs/PathRef"
    },
    "formula": {
      "description": "Formula or calculation narrative.",
      "type": "string"
    },
    "id": {
      "$ref": "#/$defs/PathRef"
    },
    "key": {
      "description": "Stable key (snake_case).",
      "type": "string"
    },
    "linked_okrs": {
      "description": "PathRefs to OKRs that consume this KPI.",
      "items": {
        "$ref": "#/$defs/PathRef"
      },
      "type": "array"
    },
    "linked_slas": {
      "description": "PathRefs to SLAs that consume this KPI.",
      "items": {
        "$ref": "#/$defs/PathRef"
      },
      "type": "array"
    },
    "name": {
      "type": "string"
    },
    "owner": {
      "$ref": "#/$defs/PathRef"
    },
    "polarity": {
      "$ref": "#/$defs/KpiPolarity"
    },
    "regulatory_refs": {
      "description": "PathRefs to regulatory disclosures.",
      "items": {
        "$ref": "#/$defs/PathRef"
      },
      "type": "array"
    },
    "status": {
      "$ref": "#/$defs/KpiStatus"
    },
    "target_value": {
      "format": "double",
      "type": "number"
    },
    "thresholds": {
      "$ref": "#/$defs/KpiThresholds"
    },
    "unit": {
      "description": "Unit (e.g. \"EUR\", \"pct\", \"count\", \"days\").",
      "type": "string"
    }
  },
  "required": [
    "id",
    "entity",
    "domain",
    "status",
    "key",
    "name",
    "description",
    "formula",
    "unit",
    "polarity",
    "cadence",
    "target_value",
    "thresholds",
    "data_source",
    "owner",
    "effective_from"
  ],
  "title": "KpiDefinition",
  "type": "object",
  "x-corpospec-pillar": "metrics"
}