title: Quantity Balance Operation
type: object
x-tags:
  - Models
description: Durable receipt for a quantity action. Earning/full void may have separate base/bonus entries; balance_delta
  is their total. Exchanges link a separate quantity-one voucher issuance. Direct redemptions consume their selected
  full cost; one explicit reversal restores that original cost. API actions use API identity; automatic earning/void use
  source-order provenance. Zero movements have no receipt.
required:
  - operation_uuid
  - operation_type
  - customer_uuid
  - loyalty_program_uuid
  - loyalty_program_type
  - loyalty_balance_uuid
  - merchant_reference
  - outlet_uuid
  - balance_after
  - balance_expires_at_after
  - balance_delta
  - ledger_entries
  - reason
  - exchange_option
  - voucher_balance_uuid
  - voucher_issuance_operation_uuid
  - redemption_option
  - amount
  - eligible_spend
  - redemption_expires_at
  - source_order_uuid
  - source_order_action
  - reverses_operation_uuid
  - created_at
properties:
  operation_uuid:
    type: string
    format: uuid
  operation_type:
    $ref: ./QuantityBalanceOperationType.yaml
  customer_uuid:
    type: string
    format: uuid
  loyalty_program_uuid:
    type: string
    format: uuid
  loyalty_program_type:
    type: string
    enum: [ stamp, point ]
  loyalty_balance_uuid:
    type: string
    format: uuid
  merchant_reference:
    type: [ string, 'null' ]
    minLength: 1
    maxLength: 255
    pattern: '^[\x21-\x7E]+$'
  outlet_uuid:
    type: string
    format: uuid
  balance_after:
    type: integer
    minimum: 0
    description: Remaining quantity quantity at the time this operation completed.
  balance_expires_at_after:
    type: [ string, 'null' ]
    format: date-time
  balance_delta:
    type: integer
    description: Signed actual quantity movement; never zero.
  ledger_entries:
    type: array
    minItems: 1
    maxItems: 2
    description: Actual ledger movements belonging to this receipt, including separate base and purchase-bonus entries. Void
      recovery records bonus deductions before base deductions.
    items:
      $ref: ./QuantityBalanceLedgerEntry.yaml
  reason:
    type: [ string, 'null' ]
    minLength: 1
    maxLength: 10000
  exchange_option:
    description: Immutable selected option at exchange time; null for other quantity movements. The voucher batch separately
      freezes its issued benefit, currency and validity.
    oneOf:
      - type: object
        required: [ uuid, quantity_cost, voucher_program_uuid ]
        properties:
          uuid:
            type: string
            format: uuid
          quantity_cost:
            type: integer
            minimum: 1
            maximum: 2147483647
          voucher_program_uuid:
            type: string
            format: uuid
      - type: 'null'
  voucher_balance_uuid:
    type: [ string, 'null' ]
    format: uuid
    description: New quantity-one voucher batch created by this exchange; null for other movements.
  voucher_issuance_operation_uuid:
    type: [ string, 'null' ]
    format: uuid
    description: Linked issuance receipt, also visible through operation lookup and searches; null for other movements.
  redemption_option:
    oneOf:
      - type: "null"
      - $ref: ./QuantityRedemptionOption.yaml
    description: Immutable selected option on a direct redemption or its reversal; null for other quantity actions.
  amount:
    oneOf:
      - type: "null"
      - $ref: ./PositiveMoney.yaml
    description: Actual positive monetary saving, copied unchanged onto the reversal. This is separate from integer
      balance_delta; null for other actions.
  eligible_spend:
    oneOf:
      - type: "null"
      - $ref: ./PositiveMoney.yaml
    description: Remaining eligible monetary spend supplied at redemption, copied onto the reversal; null for other actions.
  redemption_expires_at:
    type:
      - string
      - "null"
    format: date-time
    description: Original pre-redemption pool expiry. A reversal must occur strictly before it; null represents original
      no-expiry or an action without a discount. This deadline stays frozen even if later credits change pool validity.
  source_order_uuid:
    type: [ string, 'null' ]
    format: uuid
  source_order_action:
    oneOf:
      - type: string
        enum: [ capture, void ]
      - type: 'null'
    description: Source action that created this movement; null for manual API actions.
  reverses_operation_uuid:
    type: [ string, 'null' ]
    format: uuid
    description: Original earning for a purchase-void deduction, or original direct redemption for its explicit reversal.
      Other actions return null. Exchanges cannot be reversed.
  created_at:
    type: string
    format: date-time
