{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.elimi.africa/contracts/events/cohort.activated.v1.json",
  "title": "cohort.activated data",
  "description": "data payload for cohort.activated. Emitted by Orchestrator when a PENDING_PAYMENT cohort becomes ACTIVE after payment.completed with referenceType organization_cohort. CAP and LMS provision quota from lineItems. One wallet movement is keyed off payment.completed, not this event. Idempotent on paymentId.",
  "type": "object",
  "additionalProperties": false,
  "required": ["cohortId", "organizationId", "lineItems", "paymentId", "settlement"],
  "properties": {
    "cohortId": {
      "type": "string",
      "minLength": 1,
      "description": "Orchestrator Cohort.id (ULID)"
    },
    "organizationId": {
      "type": "string",
      "minLength": 1
    },
    "paymentId": {
      "type": "string",
      "minLength": 1,
      "description": "Orchestrator Payment.id for the cohort invoice"
    },
    "lineItems": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/lineItem" }
    },
    "settlement": { "$ref": "#/$defs/settlement" }
  },
  "$defs": {
    "lineItem": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lineItemId", "product", "slots", "unitPriceMinorUnits", "currency"],
      "properties": {
        "lineItemId": {
          "type": "string",
          "minLength": 1,
          "description": "Orchestrator CohortLineItem.id. Seat events key on this id."
        },
        "product": {
          "type": "string",
          "enum": ["lms", "cap", "workmasters"]
        },
        "slots": {
          "type": "integer",
          "minimum": 1
        },
        "unitPriceMinorUnits": {
          "type": "string",
          "pattern": "^[0-9]+$",
          "description": "Unit price in minor units (kobo) as a decimal string — never a JSON float"
        },
        "currency": {
          "type": "string",
          "minLength": 3,
          "maxLength": 3,
          "description": "ISO 4217, e.g. NGN"
        },
        "levelOfferingId": {
          "type": "string",
          "minLength": 1,
          "description": "Required when product is lms"
        },
        "centreId": {
          "type": "string",
          "minLength": 1,
          "description": "Required when product is cap"
        },
        "applicationType": {
          "type": "string",
          "enum": ["RPL", "NSQ"],
          "description": "Required when product is cap"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": { "product": { "const": "lms" } },
            "required": ["product"]
          },
          "then": {
            "required": ["levelOfferingId"],
            "properties": {
              "centreId": false,
              "applicationType": false
            }
          }
        },
        {
          "if": {
            "properties": { "product": { "const": "cap" } },
            "required": ["product"]
          },
          "then": {
            "required": ["centreId", "applicationType"],
            "properties": {
              "levelOfferingId": false
            }
          }
        },
        {
          "if": {
            "properties": { "product": { "const": "workmasters" } },
            "required": ["product"]
          },
          "then": {
            "properties": {
              "levelOfferingId": false,
              "centreId": false,
              "applicationType": false
            }
          }
        }
      ]
    },
    "settlement": {
      "type": "object",
      "additionalProperties": false,
      "description": "PlatformPolicy organization_cohort_settlement value whose effectiveFrom is at or before paidAt. split shares sum to 100. platform credits no centre (centreSharePercentage 0). centre pays 100 to those centres. LMS line items are always platform revenue and are not split.",
      "required": ["mode", "platformSharePercentage", "centreSharePercentage"],
      "properties": {
        "mode": {
          "type": "string",
          "enum": ["split", "platform", "centre"]
        },
        "platformSharePercentage": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100
        },
        "centreSharePercentage": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100
        }
      }
    }
  }
}
