{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/seggwat-com/json-schema/seggwat-com-churn-event-schema.json",
  "title": "ChurnEvent",
  "description": "A churn event representing a subscription cancellation from a payment provider",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/_original/seggwat-com-api-openapi.json#/components/schemas/ChurnEvent",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Unique identifier for the churn event"
    },
    "project_id": {
      "type": "string",
      "description": "The project this churn event belongs to"
    },
    "provider": {
      "$ref": "#/$defs/ChurnProvider"
    },
    "subscription_id": {
      "type": "string",
      "description": "Subscription identifier from the payment provider"
    },
    "customer_id": {
      "type": [
        "string",
        "null"
      ],
      "description": "Customer identifier from the payment provider (if available)"
    },
    "customer_email": {
      "type": [
        "string",
        "null"
      ],
      "description": "Customer email address (if available)"
    },
    "reason": {
      "$ref": "#/$defs/CancellationReason"
    },
    "comment": {
      "type": [
        "string",
        "null"
      ],
      "description": "Free-text cancellation comment from the customer (if provided)"
    },
    "product_name": {
      "type": [
        "string",
        "null"
      ],
      "description": "Name of the cancelled product or plan (if available)"
    },
    "canceled_at": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp when the subscription was cancelled"
    },
    "created_at": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp when the churn event was recorded in SeggWat"
    }
  },
  "required": [
    "id",
    "project_id",
    "provider",
    "subscription_id",
    "reason",
    "canceled_at",
    "created_at"
  ],
  "$defs": {
    "CancellationReason": {
      "type": "string",
      "description": "Reason the customer cancelled their subscription",
      "enum": [
        "CustomerService",
        "LowQuality",
        "MissingFeatures",
        "SwitchedService",
        "TooComplex",
        "TooExpensive",
        "Unused",
        "Other",
        "Unknown"
      ]
    },
    "ChurnProvider": {
      "type": "string",
      "description": "Payment provider that reported the cancellation",
      "enum": [
        "Polar",
        "Stripe"
      ]
    }
  }
}