using System.Collections.Generic;
using System.Data.Entity;
using OrderEntryEngine;

namespace OrderEntryDataAccess
{
    public class OrderEntryInitializer : DropCreateDatabaseAlways<OrderEntryContext>
    {
        protected override void Seed(OrderEntryContext context)
        {
            var locations = new List<Location>
            {
                new Location { Name = "NTC Bookstore", City = "Wausau", State = "WI", Description = "The school bookstore." },
                new Location { Name = "Warehouse", City = "Wausau", State = "WI", Description = "The school bookstore's storage warehouse." },
                new Location { Name = "Processing room", City = "Wausau", State = "WI", Description = "The room for processing placed orders." }
            };

            context.Locations.AddRange(locations);
            context.SaveChanges();

            var categories = new List<Category>
            {
                new Category { Name = "Electronics" },
                new Category { Name = "Apparel" },
                new Category { Name = "Household" }
            };

            context.Categories.AddRange(categories);
            context.SaveChanges();

            var graphicsCards = new List<GraphicsCard>
            {
                new GraphicsCard { Name = "EVGA GeForce GTX 950", Clock = 1190.0, Ram = 2.0 },
                new GraphicsCard { Name = "MSI Gaming RX 470", Clock = 1242.0, Ram = 8.0 },
                new GraphicsCard { Name = "Asus Turbo-GTX 970", Clock = 1088.0, Ram = 4.0 }
            };

            context.GraphicsCards.AddRange(graphicsCards);
            context.SaveChanges();

            var computers = new List<Computer>
            {
                new Computer { Name = "Apple MacBook Air", Condition = Condition.Poor, Description = "Features 4th Gen Intel Core processors and all-day battery life, yet it’s still incredibly thin and light.", Price = 888.00m, LocationId = 1, Quantity = 5, GraphicsCardId = 1 },
                new Computer { Name = "Asus Zenbook UX305", Condition = Condition.Poor, Description = "Super thin aluminum body, bright matte screen, quiet fanless design, extra long battery life.", Price = 749.00m, LocationId = 1, Quantity = 10, GraphicsCardId = 2 },
                new Computer { Name = "Dell XPS 13", Condition = Condition.Poor, Description = "Good battery life, small footprint, comfortable keyboard and attractive design.", Price = 1088.00m, LocationId = 2, Quantity = 12, GraphicsCardId = 3 },
                new Computer { Name = "Lenovo ThinkPad T450x", Condition = Condition.Excellent, Description = "Good keyboard, nice battery life with extended battery, durable design, loud and accurate audio.", Price = 640.00m, LocationId = 1, Quantity = 20, GraphicsCardId = 1 },
                new Computer { Name = "Acer Travelmate P645", Condition = Condition.Average, Description = "Sleek and lightweight, snappy keyboard, strong security features, better performance and battery life.", Price = 1030.00m, LocationId = 1, Quantity = 30, GraphicsCardId = 2 },
                new Computer { Name = "Sony Vaio Pro 13 Touch", Condition = Condition.Excellent, Description = "Excellent ultra portable laptop with more than just the latest Intel processors.", Price = 799.00m, LocationId = 1, Quantity = 2, GraphicsCardId = 3 }
            };

            context.Computers.AddRange(computers);
            context.SaveChanges();

            var computerCategories = new List<ComputerCategory>
            {
                new ComputerCategory { ComputerId = 1, CategoryId = 1 },
                new ComputerCategory { ComputerId = 2, CategoryId = 3 },
                new ComputerCategory { ComputerId = 3, CategoryId = 2 }
            };

            context.ComputerCategories.AddRange(computerCategories);
            context.SaveChanges();

            var customers = new List<Customer>
            {
                new Customer { FirstName = "Billy", LastName = "Buyer", Phone = "555-555-1234", Email = "billybuyer@example.com", Address = "111 Red Road", City = "Wausau", State = "WI" },
                new Customer { FirstName = "Sally", LastName = "Ride", Phone = "555-555-9876", Email = "astronautlady@nasa.gov", Address = "222 Orange Street", City = "Wausau", State = "WI" }
            };

            context.Customers.AddRange(customers);
            context.SaveChanges();

            var orders = new List<Order>
            {
                new Order { CustomerId = 1, Status = OrderStatus.Pending },
                new Order { CustomerId = 2, Status = OrderStatus.Pending }
            };

            context.Orders.AddRange(orders);
            context.SaveChanges();

            var lines = new List<OrderLine>
            {
                new OrderLine { OrderId = 1, ComputerId = 1, Quantity = 2 },
                new OrderLine { OrderId = 2, ComputerId = 2, Quantity = 1 },
                new OrderLine { OrderId = 2, ComputerId = 3, Quantity = 1 }
            };

            context.Lines.AddRange(lines);
            context.SaveChanges();
        }
    }
}