{%- set payment_methods = [
  "bank_transfer",
  "credit_card",
  "gift_card"
] -%}

cubes:
  - name: cube_01_1
    sql: >
      SELECT
        order_id,
        {%- for payment_method in payment_methods %}
        SUM(CASE WHEN payment_method = '{{payment_method}}' THEN amount END) AS {{payment_method}}_amount,
        {%- endfor %}
        SUM(amount) AS total_amount
      FROM app_data.payments
      GROUP BY 1
      
  - name: cube_01_2
    sql: >
      SELECT
        order_id,
        {%- for payment_method in payment_methods %}
        SUM(CASE WHEN payment_method = '{{payment_method}}' THEN amount END) AS {{payment_method}}_amount
        {%- if not loop.last %},{% endif %}
        {%- endfor %}
      FROM app_data.payments
      GROUP BY 1