{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/ordway/main/json-schema/subscription.json",
  "title": "Subscription",
  "description": "A recurring billing subscription in Ordway",
  "type": "object",
  "required": ["company_id", "subscription_id", "subscription_line_id"],
  "properties": {
    "company_id": {
      "type": "string",
      "description": "Identifier for the Ordway company account"
    },
    "subscription_id": {
      "type": "string",
      "description": "Unique identifier for the subscription"
    },
    "subscription_line_id": {
      "type": "string",
      "description": "Unique identifier for the subscription line item"
    },
    "customer_id": {
      "type": "string",
      "description": "ID of the customer this subscription belongs to"
    },
    "status": {
      "type": ["string", "null"],
      "enum": ["active", "cancelled", "suspended", "pending", "expired", null],
      "description": "Current subscription status"
    },
    "billing_start_date": {
      "type": ["string", "null"],
      "format": "date",
      "description": "Date when billing begins"
    },
    "service_start_date": {
      "type": ["string", "null"],
      "format": "date",
      "description": "Date when the service starts"
    },
    "contract_effective_date": {
      "type": ["string", "null"],
      "format": "date",
      "description": "Date when the contract takes effect"
    },
    "cancellation_date": {
      "type": ["string", "null"],
      "format": "date",
      "description": "Date when the subscription was or will be cancelled"
    },
    "auto_renew": {
      "type": ["boolean", "null"],
      "description": "Whether the subscription auto-renews at end of term"
    },
    "currency": {
      "type": ["string", "null"],
      "description": "Billing currency (ISO 4217)"
    },
    "payment_terms": {
      "type": ["string", "null"],
      "description": "Payment terms for invoices generated by this subscription"
    },
    "cmrr": {
      "type": ["number", "null"],
      "description": "Contracted Monthly Recurring Revenue for this subscription line"
    },
    "contract_term": {
      "type": ["string", "null"],
      "description": "Contract term duration"
    },
    "renewal_term": {
      "type": ["string", "null"],
      "description": "Renewal term duration"
    },
    "product_id": {
      "type": ["string", "null"],
      "description": "ID of the product"
    },
    "product_name": {
      "type": ["string", "null"],
      "description": "Name of the product"
    },
    "plan_name": {
      "type": ["string", "null"],
      "description": "Name of the billing plan"
    },
    "charge_id": {
      "type": ["string", "null"],
      "description": "ID of the charge"
    },
    "charge_name": {
      "type": ["string", "null"],
      "description": "Name of the charge"
    },
    "pricing_model": {
      "type": ["string", "null"],
      "enum": ["flat_fee", "per_unit", "tiered", "volume", "usage_based", null],
      "description": "Pricing model for this charge"
    },
    "list_price": {
      "type": ["number", "null"],
      "description": "List price before discounts"
    },
    "quantity": {
      "type": ["number", "null"],
      "description": "Quantity for per-unit pricing"
    },
    "discount": {
      "type": ["number", "null"],
      "description": "Discount percentage applied"
    },
    "effective_price": {
      "type": ["number", "null"],
      "description": "Effective price after discounts"
    },
    "charge_type": {
      "type": ["string", "null"],
      "enum": ["recurring", "one_time", "usage", null],
      "description": "Type of charge"
    },
    "billing_period": {
      "type": ["string", "null"],
      "enum": ["monthly", "quarterly", "semi_annual", "annual", "one_time", null],
      "description": "Billing frequency"
    },
    "current_period_start_date": {
      "type": ["string", "null"],
      "format": "date",
      "description": "Start of current billing period"
    },
    "current_period_end_date": {
      "type": ["string", "null"],
      "format": "date",
      "description": "End of current billing period"
    },
    "billing_schedule_id": {
      "type": ["string", "null"],
      "description": "ID of associated billing schedule"
    },
    "revenue_schedule_id": {
      "type": ["string", "null"],
      "description": "ID of associated revenue recognition schedule"
    },
    "prorate_partial_periods": {
      "type": ["boolean", "null"],
      "description": "Whether to prorate charges for partial billing periods"
    },
    "exchange_rate": {
      "type": ["number", "null"],
      "description": "Currency exchange rate applied"
    },
    "custom_fields": {
      "type": ["object", "null"],
      "additionalProperties": true,
      "description": "User-defined custom fields"
    },
    "created_by": {
      "type": ["string", "null"],
      "description": "User who created the record"
    },
    "updated_by": {
      "type": ["string", "null"],
      "description": "User who last updated the record"
    },
    "created_date": {
      "type": ["string", "null"],
      "format": "date-time",
      "description": "Timestamp when the record was created"
    },
    "updated_date": {
      "type": ["string", "null"],
      "format": "date-time",
      "description": "Timestamp when the record was last updated"
    }
  }
}
