# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
#   cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
#   Mayor.create(name: 'Emanuel', city: cities.first)

require 'usda_importer'

puts "Seeding..."

dan = User.create!({username: 'dan', full_name: 'Dan', email: 'dan.elbert@gmail.com', password: 'qwerty', password_confirmation: 'qwerty'})

foods = {
    water:        {name: 'Water', density: '1 g/ml'},
    butter:       {name: 'Butter, Salted', ndbn: '01001'},
    butter_sal:   {name: 'Butter, Unsalted', density: '226 gram/cup'},
    flour:        {name: 'Flour, Bleached All Purpose', density: '130 gram/cup'},
    flour_cake:   {name: 'Flour, Cake', density: '120 gram/cup'},
    flour_wheat:  {name: 'Flour, Whole Wheat', density: '130 gram/cup'},
    cornstarch:   {name: 'Cornstarch', ndbn: '20027'},
    cornmeal:     {name: 'Cornmeal', density: '120 gram/cup'},
    sugar:        {name: 'Sugar, Granulated', ndbn: '19335'},
    sugar_brown:  {name: 'Sugar, Brown, Lightly Packed', density: '210 gram/cup'},
    sugar_powder: {name: 'Sugar, Powdered', density: '120 gram/cup'},
    chips:        {name: 'Chocolate Chips', density: '170 gram/cup'},
    cocoa:        {name: 'Cocoa Powder', density: '100 gram/cup'},
    salt:         {name: 'Salt, Kosher', density: '248 gram/cup'},
    table_salt:   {name: 'Salt, Table', density: '304 gram/cup'},
    whole_milk:   {name: 'Milk, Whole', density: '1.028 gram/ml'},
    skim_milk:    {name: 'Milk, Skim', density: '1.032 gram/ml'},
    two_per_milk: {name: 'Milk, 2%', density: '1.03 gram/ml'}       ,
    flank:        {name: 'Flank Steak', ndbn: '13970'},
    soy_sauce:    {name: 'Soy Sauce', ndbn: '16123'},
    shaoxing:     {name: 'Shaoxing Wine', ndbn: '14084'},
    stock:        {name: 'Chicken Stock, Low Sodium', ndbn: '06970'}          ,
    oyster_sauce: {name: 'Oyster Sauce', ndbn: '06176'},
    seasame_oil:  {name: 'Sesame Seed Oil', ndbn: '04058'}    ,
    garlic:       {name: 'Garlic', ndbn: '11215'},
    peanut_oil:   {name: 'Peanut Oil', ndbn: '04042'},
    broccoli:     {name: 'Broccoli Florets', ndbn: '11740'}

}

foods.each do |k, v|
  foods[k] = Food.create!({user_id: dan.id}.merge(v))
end

g = Recipe.create!({
    name: 'Guacamole',
    yields: '1 cup',
    total_time: 15,
    active_time: 15,
    user_id: dan.id
                   })

g.tag_names = ['vegan', 'vegetarian', 'appetizer']

bb = Recipe.create!({
                      name: 'Beef and Broccoli With Oyster Sauce',
                      source: 'http://www.seriouseats.com/recipes/2012/06/chinese-american-beef-and-broccoli-with-oyster-sauce-recipe.html',
                      yields: 4,
                      total_time: 30,
                      active_time: 10,
                      user_id: dan.id
                    })

bb.tag_names = ['beef', 'dinner', 'stirfry']

[
    {quantity: '1', units: 'pound', preparation: 'flank steak, skirt steak, hanger steak, or flap meat, cut into 1/4-inch thick strips', food: foods[:flank]},
    {quantity: '1/4', units: 'cup', preparation: 'divided', food: foods[:soy_sauce]},
    {quantity: '1/4', units: 'cup', preparation: 'divided', food: foods[:shaoxing]},
    {quantity: '2', units: 'teaspoons', preparation: '', food: foods[:cornstarch]},
    {quantity: '1/3', units: 'cup', preparation: '', food: foods[:stock]},
    {quantity: '1/4', units: 'cup', preparation: '', food: foods[:oyster_sauce]},
    {quantity: '1', units: 'tablespoon', preparation: '', food: foods[:sugar]},
    {quantity: '1', units: 'teaspoon', preparation: '', food: foods[:seasame_oil]},
    {quantity: '2', units: 'medium cloves', preparation: 'finely minced', food: foods[:garlic]},
    {quantity: '2', units: 'teaspoons', preparation: 'finely minced', name: 'ginger root'},
    {quantity: '3', units: '', preparation: 'whites finely sliced, greens cut into 1/2-inch segments, reserved separately', name: 'Scallions'},
    {quantity: '4', units: 'tablespoons', preparation: '', food: foods[:peanut_oil]},
    {quantity: '1', units: 'pound', preparation: '', food: foods[:broccoli]},
].each_with_index do |ri, i|
  RecipeIngredient.create!({recipe: bb, sort_order: i}.merge(ri))
end


importer = UsdaImporter.new(Rails.root.join('vendor', 'data', 'usda'))
importer.import


puts "Seeds planted."
