using System;
using System.Data.Entity;
using Rainbow.Models;

namespace Rainbow.Data.Configuration
{
    public class CustomDatabaseInitializer : DropCreateDatabaseAlways<RainbowContext>
    {
        protected override void Seed(RainbowContext context)
        {
            // Registrar
            var registrar = new Registrar
            {
                Name = "Sample Registrar"
            };
            context.Registrars.Add(registrar);

            // web-crossing
            var customer = new Customer
            {
                Number = "00001",
                Type = CustomerType.Reseller,
                CompanyName = "web-crossing GmbH",
                DirectoryName = "web-crossing GmbH",
                StreetAddress = "Eduard-Bodem-Gasse 8",
                Zip = "6020",
                City = "Innsbruck",
                Country = "Österreich",
                Email = "info@web-crossing.com"
            };
            context.Customers.Add(customer);

            var domain = new Domain
            {
                Name = "web-crossing.com",
                Active = true,
                ReservationStart = new DateTime(1999, 8, 14),
                ReservationEnd = new DateTime(1999, 9, 14)
            };
            customer.Domains.Add(domain);
            registrar.Domains.Add(domain);

            domain = new Domain
            {
                Name = "webhome.at",
                Active = true,
                ReservationStart = new DateTime(1999, 9, 16),
                ReservationEnd = new DateTime(1999, 10, 17)
            };
            customer.Domains.Add(domain);
            registrar.Domains.Add(domain);

            var project = new Project
            {
                Name = "Website www.web-crossing.com",
                Description = "Testbeschreibung",
                DirectoryName = "Website www.web-crossing.com",
                Customer = customer,
                Deadline = new DateTime(2013, 10, 8),
                FlatRate = true,
                Active = true
            };
            customer.Projects.Add(project);

            var timeSheetEntry = new TimeSheetEntry
            {
                Project = project,
                StartTime = DateTime.Now.AddMinutes(-30),
                EndTime = DateTime.Now,
                Description = "Arbeit an Rainbow"
            };
            project.TimeSheetEntries.Add(timeSheetEntry);

            var ticket = new Ticket
            {
                Project = project,
                Title = "Testticket 1",
                Description = "Das ist eine Testbeschreibung für Testticket 1",
                Status = TicketStatus.Open,
                Priority = TicketPriority.P1,
                Severity = TicketSeverity.Major
            };
            project.Tickets.Add(ticket);
            var ticketResponse = new TicketResponse
            {
                Ticket = ticket,
                Description = "Das ist eine Antwort auf Testticket 1"
            };
            ticket.Responses.Add(ticketResponse);

            ticket = new Ticket
            {
                Project = project,
                Title = "Testticket 2",
                Description = "Das ist eine Testbeschreibung für Testticket 2",
                Status = TicketStatus.Open,
                Priority = TicketPriority.P2,
                Severity = TicketSeverity.Enhancement
            };
            project.Tickets.Add(ticket);

            context.SaveChanges();

            // STASTO
            customer = new Customer
            {
                Number = "00002",
                Type = CustomerType.EndCustomer,
                CompanyName = "STASTO Ing. Stocker KG",
                DirectoryName = "STASTO Ing. Stocker KG",
                StreetAddress = "Feldstraße 11",
                Zip = "6020",
                City = "Innsbruck",
                Country = "Österreich",
                Email = "office@stasto.com"
            };
            context.Customers.Add(customer);

            domain = new Domain
            {
                Name = "stasto.com",
                Active = true,
                ReservationStart = new DateTime(1998, 3, 1),
                ReservationEnd = new DateTime(1999, 3, 1)
            };
            customer.Domains.Add(domain);
            registrar.Domains.Add(domain);

            project = new Project
            {
                Name = "Website www.stasto.com",
                DirectoryName = "Website www.stasto.com",
                Customer = customer,
                Active = true
            };
            customer.Projects.Add(project);

            context.SaveChanges();

            // Servers
            var server = new Server
            {
                HostName = "sv2.web-crossing.com",
                OperatingSystem = "Windows Server 2003 Web Edition",
                HardwareDescription = "VMWare"
            };
            server.IpAddresses.Add(new IpAddress { Address = "82.150.199.45" });
            context.Servers.Add(server);

            server = new Server
            {
                HostName = "sv16.web-crossing.com",
                OperatingSystem = "Windows Server 2008 Web Edition",
                HardwareDescription = "VMWare"
            };
            server.IpAddresses.Add(new IpAddress { Address = "82.150.199.17" });
            context.Servers.Add(server);

            server = new Server
            {
                HostName = "sv21.web-crossing.com",
                OperatingSystem = "Ubuntu",
                HardwareDescription = "Xen"
            };
            server.IpAddresses.Add(new IpAddress { Address = "82.150.199.192" });
            context.Servers.Add(server);

            base.Seed(context);
        }
    }
}