using FakturyWeb.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;

namespace RazorPagesMovie.Models
{
  public static class SeedData
  {
    public static void Initialize(IServiceProvider serviceProvider)
    {
      using (var context = new FakturyWebContext(
          serviceProvider.GetRequiredService<
              DbContextOptions<FakturyWebContext>>()))
      {
        context.Database.ExecuteSqlRaw("DELETE FROM FAKTURA");
        context.Database.ExecuteSqlRaw("DELETE FROM ZAKAZNIK");
        context.ZAKAZNIK.AddRange(
            new ZAKAZNIK
            {
              JMENO = "Kowalski",
              PRIJMENI = "Don"
            },

            new ZAKAZNIK
            {
              JMENO = "Petr",
              PRIJMENI = "Zajíc",
              ULICE = "Větrná 622",
              MESTO = "Stráž nad Nisou",
              PSC = "46330",
              IC="12345678",
              DIC="2255881054"
            },

            new ZAKAZNIK
            {
              JMENO = "Kowalski 6",
              PRIJMENI = "Don"
            },

            new ZAKAZNIK
            {
              JMENO = "Kowalski 7",
              PRIJMENI = "Don"
            }
        );

        context.Database.ExecuteSqlRaw("DELETE FROM UZIVATEL");
        context.UZIVATEL.Add(
          new UZIVATEL
          {
            JMENO = "Kowalski",
            PRIJMENI = "Tučňák",
            ULICE = "Žitavská 558",
            MESTO = "Hrádek nad Nisou",
            PSC = "46334",
            IC = "88062023",
            DIC = "8708081085",
            TELEFON = "723 833 483",
            EMAIL = "kmet.p@seznam.cz",
            BANKA = "226282805/0300",
            WEB = "www.kmetix.cz",
            FAKTURA_CISLOVANI = 1,
            FAKTURA_SPLATNOST = 15,
            FAKTURA_MASKA = "(ROK)(CISLO4)"
          }
        );

        context.SaveChanges();
      }
    }
  }
}