class Users::ProductSerializer
  include Qwaiter::UserBaseSerializer
  HOST = Rails.application.config.action_controller.asset_host.to_s
  attributes :name, :price, :description, :code, :position, :visible, :active
  attribute :image do
    if object.image.present?
      {
        thumb: File.join(HOST, object.image.url(:thumb).to_s),
        small: File.join(HOST, object.image.url(:small).to_s)
      }
    else
      dummy = File.join(HOST, object.image.url.to_s)
      {thumb: dummy, small: dummy}
    end
  end

  has_many :product_variants, serializer: Users::ProductVariantSerializer
end
