{
  "$defs": {
    "ComplianceWindow": {
      "description": "Compliance window (rolling vs calendar).",
      "oneOf": [
        {
          "const": "rolling28d",
          "description": "Rolling 28-day.",
          "type": "string"
        },
        {
          "const": "rolling30d",
          "description": "Rolling 30-day.",
          "type": "string"
        },
        {
          "const": "rolling90d",
          "description": "Rolling 90-day.",
          "type": "string"
        },
        {
          "const": "calendar_month",
          "description": "Calendar month.",
          "type": "string"
        },
        {
          "const": "calendar_quarter",
          "description": "Calendar quarter.",
          "type": "string"
        },
        {
          "const": "calendar_year",
          "description": "Calendar year.",
          "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"
    },
    "SlaCreditTier": {
      "description": "SLA credit tier.",
      "properties": {
        "breach_threshold_pct": {
          "description": "SLO breach floor (e.g. 99.0 means \"actual ≤ 99.0%\").",
          "format": "double",
          "type": "number"
        },
        "credit_pct": {
          "description": "Credit as % of monthly fees.",
          "format": "double",
          "type": "number"
        }
      },
      "required": [
        "breach_threshold_pct",
        "credit_pct"
      ],
      "type": "object"
    },
    "SlaPeriodResult": {
      "description": "Period result (for last-window report).",
      "properties": {
        "actual_pct": {
          "format": "double",
          "type": "number"
        },
        "breached": {
          "type": "boolean"
        },
        "credit_pct_owed": {
          "description": "Credit owed (if any) as % of monthly fees.",
          "format": "double",
          "type": [
            "number",
            "null"
          ]
        },
        "period_end": {
          "$ref": "#/$defs/IsoDate"
        },
        "period_start": {
          "$ref": "#/$defs/IsoDate"
        }
      },
      "required": [
        "period_start",
        "period_end",
        "actual_pct",
        "breached"
      ],
      "type": "object"
    },
    "Sli": {
      "description": "One SLI definition.",
      "properties": {
        "key": {
          "type": "string"
        },
        "kind": {
          "$ref": "#/$defs/SliKind"
        },
        "latency_threshold_ms": {
          "description": "Latency threshold ms when kind == Latency.",
          "format": "double",
          "type": [
            "number",
            "null"
          ]
        },
        "percentile": {
          "description": "Percentile when kind == Latency (e.g. 99.0 = p99).",
          "format": "double",
          "type": [
            "number",
            "null"
          ]
        },
        "specification": {
          "description": "Free-form query / formula (e.g. PromQL, log query).",
          "type": "string"
        }
      },
      "required": [
        "key",
        "kind",
        "specification"
      ],
      "type": "object"
    },
    "SliKind": {
      "description": "SLI kind.",
      "oneOf": [
        {
          "const": "availability",
          "description": "Availability — fraction of successful requests.",
          "type": "string"
        },
        {
          "const": "latency",
          "description": "Latency at a percentile (must specify percentile + threshold).",
          "type": "string"
        },
        {
          "const": "throughput",
          "description": "Throughput / capacity.",
          "type": "string"
        },
        {
          "const": "error_rate",
          "description": "Error rate (% of requests).",
          "type": "string"
        },
        {
          "const": "freshness",
          "description": "Freshness — data staleness.",
          "type": "string"
        },
        {
          "const": "durability",
          "description": "Durability — data loss rate.",
          "type": "string"
        },
        {
          "const": "correctness",
          "description": "Correctness — fraction of correct results.",
          "type": "string"
        }
      ]
    },
    "Slo": {
      "description": "One SLO target.",
      "properties": {
        "backed_by_sla": {
          "description": "Whether SLO breach triggers a customer credit (SLA-backed).",
          "type": "boolean"
        },
        "key": {
          "type": "string"
        },
        "sli_key": {
          "description": "SLI it targets.",
          "type": "string"
        },
        "target_pct": {
          "description": "Target value (0.0-100.0). For availability: % of good requests.",
          "format": "double",
          "type": "number"
        },
        "window": {
          "$ref": "#/$defs/ComplianceWindow"
        }
      },
      "required": [
        "key",
        "sli_key",
        "target_pct",
        "window",
        "backed_by_sla"
      ],
      "type": "object"
    }
  },
  "$id": "https://corpospec.com/schemas/v0.16.0/service-level-agreement.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "SLA + SLO record (one per service).",
  "properties": {
    "contract_ref": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "PathRef to the underlying contract."
    },
    "credit_cap_pct": {
      "description": "Maximum credit per period (% of monthly fee).",
      "format": "double",
      "type": "number"
    },
    "credit_tiers": {
      "description": "SLA credit bands (sorted ascending by breach_threshold_pct).",
      "items": {
        "$ref": "#/$defs/SlaCreditTier"
      },
      "type": "array"
    },
    "customer": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "PathRef to the customer (None ⇒ default SLA for all tiers)."
    },
    "effective_from": {
      "$ref": "#/$defs/IsoDate"
    },
    "effective_to": {
      "anyOf": [
        {
          "$ref": "#/$defs/IsoDate"
        },
        {
          "type": "null"
        }
      ]
    },
    "entity": {
      "$ref": "#/$defs/PathRef"
    },
    "exclusions": {
      "description": "Exclusions (planned maintenance, force majeure).",
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "id": {
      "$ref": "#/$defs/PathRef"
    },
    "name": {
      "type": "string"
    },
    "owner": {
      "$ref": "#/$defs/PathRef"
    },
    "period_history": {
      "description": "Last period results.",
      "items": {
        "$ref": "#/$defs/SlaPeriodResult"
      },
      "type": "array"
    },
    "service": {
      "$ref": "#/$defs/PathRef",
      "description": "PathRef to the service / product."
    },
    "slis": {
      "items": {
        "$ref": "#/$defs/Sli"
      },
      "type": "array"
    },
    "slos": {
      "items": {
        "$ref": "#/$defs/Slo"
      },
      "type": "array"
    }
  },
  "required": [
    "id",
    "entity",
    "service",
    "name",
    "slis",
    "slos",
    "credit_tiers",
    "credit_cap_pct",
    "exclusions",
    "effective_from",
    "owner"
  ],
  "title": "ServiceLevelAgreement",
  "type": "object",
  "x-corpospec-pillar": "operations"
}