title: Quantity Balance
type: object
x-tags:
  - Models
description: "A pooled integer quantity balance for one customer/program. Availability is independent of reward choices,
  earning dates and tier eligibility: positive valid units remain available with no configured options or insufficient
  units for every reward. Archive blocks spending. Both direct discounts and voucher exchanges spend the same pool;
  affordability is advisory and does not promise eligibility."
required:
  - uuid
  - type
  - customer_uuid
  - loyalty_program
  - currency_code
  - timezone
  - balance
  - available_balance
  - usable_from
  - expires_at
  - state
  - is_usable
  - exchange_options
  - redemption_options
  - created_at
properties:
  uuid:
    type: string
    format: uuid
  type:
    type: string
    enum:
      - stamp
      - point
  customer_uuid:
    type: string
    format: uuid
  loyalty_program:
    $ref: ./LoyaltyProgram.yaml
    description: The program's current name, description, outlet restrictions and configuration.
  currency_code:
    type: string
    minLength: 3
    maxLength: 3
    example: SGD
    description: The program currency used for voucher rewards. Quantity quantities are integers, not monetary amounts.
  timezone:
    type: string
    example: Asia/Singapore
    description: The merchant's IANA time zone.
  balance:
    type: integer
    minimum: 0
    description: The recorded quantity quantity, including units that cannot currently be used.
  available_balance:
    type: integer
    minimum: 0
    description: The quantity quantity when state is available, otherwise zero. This does not deduct any option cost.
  usable_from:
    type: string
    format: date-time
    pattern: ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$
    description: When the balance was created. Later additions do not change this date.
    example: 2026-10-27T00:00:00Z
  expires_at:
    type:
      - string
      - "null"
    format: date-time
    pattern: ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$
  state:
    description: An empty balance reports insufficient_balance before expiry or program restrictions.
    type: string
    enum:
      - available
      - expired
      - insufficient_balance
      - archived
  is_usable:
    type: boolean
    description: True when state is available. This describes baseline balance availability, even with no affordable
      exchange options. Exchange also checks the current PIN, source outlet and destination voucher issuance conditions.
  exchange_options:
    type: array
    description: Exchange options with resolvable voucher programs and their current display details, retaining
      configuration order. This list can be empty. Unresolved destinations are omitted; existing archived programs
      remain included. Affordability uses available_balance and quantity_cost only. Destination voucher eligibility,
      validity and lifetime issuance limits are checked when exchanging; sufficient units do not guarantee a successful
      exchange. Destination outlets govern later voucher redemption.
    items:
      type: object
      required:
        - uuid
        - quantity_cost
        - voucher_program_uuid
        - voucher_program
        - is_affordable
      properties:
        uuid:
          type: string
          format: uuid
        quantity_cost:
          type: integer
          minimum: 1
          maximum: 2147483647
        voucher_program_uuid:
          type: string
          format: uuid
        voucher_program:
          description: Current display details for the configured voucher destination. These are current program settings, not
            frozen issued-voucher terms or a promise of exchange eligibility. Issuance limits are configured limits, not
            remaining capacity. Options without a resolvable voucher program in the balance's merchant are omitted from
            exchange_options. Archived programs remain included.
          type: object
          required:
            - uuid
            - name
            - currency_code
            - outlet_uuids
            - voucher_configuration
          properties:
            uuid:
              type: string
              format: uuid
            name:
              type: string
              minLength: 1
              maxLength: 255
            currency_code:
              type: string
              minLength: 3
              maxLength: 3
              example: SGD
            outlet_uuids:
              type: array
              description: Current restrictions on later voucher redemption. An empty list permits all current and future outlets
                belonging to the merchant; these outlets do not restrict voucher issuance.
              items:
                type: string
                format: uuid
            voucher_configuration:
              $ref: ./VoucherConfiguration.yaml
              description: Current benefit calculation, minimum eligible spend, stackability, configured validity and issuance limits.
                Rolling validity is resolved when the voucher is issued. After exchange, use the issued voucher
                balance's terms, usable_from and expires_at for its saved benefit and validity; minimum spend, outlets
                and stacking remain current redemption conditions.
        is_affordable:
          type: boolean
          description: True when available_balance meets quantity_cost. This describes affordability only; it does not check
            destination voucher eligibility or reserve capacity.
  redemption_options:
    type: array
    description: Current direct-discount options, in configuration order. Affordability uses available units only;
      exchange/redemption still checks PIN, archive/outlets, selected terms and remaining eligible spend.
    items:
      allOf:
        - $ref: ./QuantityRedemptionOption.yaml
        - type: object
          required:
            - is_affordable
          properties:
            is_affordable:
              type: boolean
  created_at:
    type: string
    format: date-time
    pattern: ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$
