namespace :supplier do
  task export_menu: :environment do
    supplier_name = ARGV[1]
    raise "Please supply a suppliers' name as argument" unless supplier_name.present?
    supplier = Supplier.find_by_name(supplier_name)
    raise "Cannot find supplier with name #{supplier_name}" unless supplier.present?
    object = supplier.product_categories.sort_by(&:position).map do |pc|
      { pc.name => pc.products.map{ |product|
        {
          name: product.name.to_s.strip.presence,
          description: product.description.presence,
          price: product.price,
          product_variants: product.product_variants.map(&:name)
        }}
      }
    end
    puts object.to_yaml
  end
end
