class OrderSerializer
  include JSONAPI::Serializer
  attributes :number
  belongs_to :shopping_cart, meta: (proc do |order, _params|
    order.shopping_cart.total
  end)
  belongs_to :orderable, serializer: TrackSerializer, meta: (proc do |order, params|
    if params[:user_purchases]
      TrackSerializer.new(order.orderable, { params: { no_related: false, user_purchases: params[:user_purchases] } })
    else
      { item: order.orderable, size: order.orderable.purchases.size }
    end
  end)

  belongs_to :license, meta: (proc do |order, _params|
    { price: order.license.price_cents, currency: order.license.price_currency }
  end)
end
