using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace DataImport.Models
{
    public partial class SASContext : DbContext
    {
        public SASContext()
        {
        }

        public SASContext(DbContextOptions<SASContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Brand> Brands { get; set; } = null!;
        public virtual DbSet<Category> Categories { get; set; } = null!;
        public virtual DbSet<Citizen> Citizens { get; set; } = null!;
        public virtual DbSet<Color> Colors { get; set; } = null!;
        public virtual DbSet<Company> Companies { get; set; } = null!;
        public virtual DbSet<DivisionGibdd> DivisionGibdds { get; set; } = null!;
        public virtual DbSet<DriveType> DriveTypes { get; set; } = null!;
        public virtual DbSet<Employee> Employees { get; set; } = null!;
        public virtual DbSet<EngineType> EngineTypes { get; set; } = null!;
        public virtual DbSet<Extension> Extensions { get; set; } = null!;
        public virtual DbSet<File> Files { get; set; } = null!;
        public virtual DbSet<Job> Jobs { get; set; } = null!;
        public virtual DbSet<License> Licenses { get; set; } = null!;
        public virtual DbSet<LicenseCategory> LicenseCategories { get; set; } = null!;
        public virtual DbSet<LoginAttempt> LoginAttempts { get; set; } = null!;
        public virtual DbSet<LoginBlock> LoginBlocks { get; set; } = null!;
        public virtual DbSet<Model> Models { get; set; } = null!;
        public virtual DbSet<Region> Regions { get; set; } = null!;
        public virtual DbSet<RegionCode> RegionCodes { get; set; } = null!;
        public virtual DbSet<Role> Roles { get; set; } = null!;
        public virtual DbSet<Transport> Transports { get; set; } = null!;
        public virtual DbSet<TransportOwnership> TransportOwnerships { get; set; } = null!;
        public virtual DbSet<TransportPhoto> TransportPhotos { get; set; } = null!;

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer("Data Source=srv-wsr\\is4;User Id=user12;Password=is4-user12;Initial Catalog=SAS;Encrypt=False");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Brand>(entity =>
            {
                entity.ToTable("Brand");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.Name)
                    .HasMaxLength(35)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<Category>(entity =>
            {
                entity.ToTable("Category");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.Name)
                    .HasMaxLength(3)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<Citizen>(entity =>
            {
                entity.ToTable("Citizen");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.Comment)
                    .HasMaxLength(300)
                    .IsUnicode(false);

                entity.Property(e => e.CurrentAddress)
                    .HasMaxLength(150)
                    .IsUnicode(false);

                entity.Property(e => e.Discription)
                    .HasMaxLength(300)
                    .IsUnicode(false);

                entity.Property(e => e.Email)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.MailIndex)
                    .HasMaxLength(6)
                    .IsUnicode(false);

                entity.Property(e => e.Name)
                    .HasMaxLength(25)
                    .IsUnicode(false);

                entity.Property(e => e.PassNumber)
                    .HasMaxLength(6)
                    .IsUnicode(false);

                entity.Property(e => e.PassSeries)
                    .HasMaxLength(4)
                    .IsUnicode(false);

                entity.Property(e => e.Patronymic)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.Phone)
                    .HasMaxLength(16)
                    .IsUnicode(false);

                entity.Property(e => e.RegistrationAddress)
                    .HasMaxLength(150)
                    .IsUnicode(false);

                entity.Property(e => e.Surname)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.HasOne(d => d.JobNavigation)
                    .WithMany(p => p.Citizens)
                    .HasForeignKey(d => d.Job)
                    .HasConstraintName("FK_Citizen_Job");

                entity.HasOne(d => d.PhotoNavigation)
                    .WithMany(p => p.Citizens)
                    .HasForeignKey(d => d.Photo)
                    .HasConstraintName("FK_Citizen_File");
            });

            modelBuilder.Entity<Color>(entity =>
            {
                entity.ToTable("Color");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.DiscriptionEng)
                    .HasMaxLength(35)
                    .IsUnicode(false);

                entity.Property(e => e.DiscriptionRus)
                    .HasMaxLength(35)
                    .IsUnicode(false);

                entity.Property(e => e.Hex)
                    .HasMaxLength(7)
                    .HasColumnName("HEX")
                    .IsFixedLength();

                entity.Property(e => e.NameEng)
                    .HasMaxLength(35)
                    .IsUnicode(false);

                entity.Property(e => e.NameRus)
                    .HasMaxLength(35)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<Company>(entity =>
            {
                entity.ToTable("Company");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.Name)
                    .HasMaxLength(50)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<DivisionGibdd>(entity =>
            {
                entity.ToTable("DivisionGIBDD");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.Name)
                    .HasMaxLength(50)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<DriveType>(entity =>
            {
                entity.ToTable("DriveType");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.Name)
                    .HasMaxLength(35)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<Employee>(entity =>
            {
                entity.ToTable("Employee");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.DivisionGibdd).HasColumnName("DivisionGIBDD");

                entity.Property(e => e.Login)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.Name)
                    .HasMaxLength(25)
                    .IsUnicode(false);

                entity.Property(e => e.Password)
                    .HasMaxLength(256)
                    .IsUnicode(false);

                entity.Property(e => e.Patronymic)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.Surname)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.HasOne(d => d.DivisionGibddNavigation)
                    .WithMany(p => p.Employees)
                    .HasForeignKey(d => d.DivisionGibdd)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Employee_DivisionGIBDD");

                entity.HasOne(d => d.RoleNavigation)
                    .WithMany(p => p.Employees)
                    .HasForeignKey(d => d.Role)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Employee_Role");
            });

            modelBuilder.Entity<EngineType>(entity =>
            {
                entity.ToTable("EngineType");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.NameEng)
                    .HasMaxLength(35)
                    .IsUnicode(false);

                entity.Property(e => e.NameRus)
                    .HasMaxLength(35)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<Extension>(entity =>
            {
                entity.ToTable("Extension");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.Name)
                    .HasMaxLength(6)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<File>(entity =>
            {
                entity.ToTable("File");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.Name)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.HasOne(d => d.ExtensionNavigation)
                    .WithMany(p => p.Files)
                    .HasForeignKey(d => d.Extension)
                    .HasConstraintName("FK_File_Extension");
            });

            modelBuilder.Entity<Job>(entity =>
            {
                entity.ToTable("Job");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.Name)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.HasOne(d => d.CompanyNavigation)
                    .WithMany(p => p.Jobs)
                    .HasForeignKey(d => d.Company)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Job_Company");
            });

            modelBuilder.Entity<License>(entity =>
            {
                entity.ToTable("License");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.DateStart).HasColumnType("date");

                entity.Property(e => e.DiateFinish).HasColumnType("date");

                entity.Property(e => e.Number)
                    .HasMaxLength(6)
                    .IsUnicode(false);

                entity.Property(e => e.Series)
                    .HasMaxLength(4)
                    .IsUnicode(false);

                entity.HasOne(d => d.CitizenNavigation)
                    .WithMany(p => p.Licenses)
                    .HasForeignKey(d => d.Citizen)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_License_License");
            });

            modelBuilder.Entity<LicenseCategory>(entity =>
            {
                entity.ToTable("LicenseCategory");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.HasOne(d => d.CategoryNavigation)
                    .WithMany(p => p.LicenseCategories)
                    .HasForeignKey(d => d.Category)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_LicenseCategory_Category");

                entity.HasOne(d => d.LicenseNavigation)
                    .WithMany(p => p.LicenseCategories)
                    .HasForeignKey(d => d.License)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_LicenseCategory_License");
            });

            modelBuilder.Entity<LoginAttempt>(entity =>
            {
                entity.ToTable("LoginAttempt");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.HasOne(d => d.EmployeeNavigation)
                    .WithMany(p => p.LoginAttempts)
                    .HasForeignKey(d => d.Employee)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_LoginAttempt_Employee");
            });

            modelBuilder.Entity<LoginBlock>(entity =>
            {
                entity.ToTable("LoginBlock");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.HasOne(d => d.EmployeeNavigation)
                    .WithMany(p => p.LoginBlocks)
                    .HasForeignKey(d => d.Employee)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_LoginBlock_Employee");
            });

            modelBuilder.Entity<Model>(entity =>
            {
                entity.ToTable("Model");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.Name)
                    .HasMaxLength(35)
                    .IsUnicode(false);

                entity.HasOne(d => d.BrandNavigation)
                    .WithMany(p => p.Models)
                    .HasForeignKey(d => d.Brand)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Model_Brand");
            });

            modelBuilder.Entity<Region>(entity =>
            {
                entity.ToTable("Region");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.Iso31662)
                    .HasMaxLength(7)
                    .IsUnicode(false)
                    .HasColumnName("ISO3166_2");

                entity.Property(e => e.NameEng)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.NameRus)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.Number)
                    .HasMaxLength(3)
                    .IsUnicode(false);

                entity.Property(e => e.Okato)
                    .HasMaxLength(3)
                    .IsUnicode(false)
                    .HasColumnName("OKATO");
            });

            modelBuilder.Entity<RegionCode>(entity =>
            {
                entity.ToTable("RegionCode");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.Code)
                    .HasMaxLength(3)
                    .IsUnicode(false);

                entity.HasOne(d => d.RegionNavigation)
                    .WithMany(p => p.RegionCodes)
                    .HasForeignKey(d => d.Region)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_RegionCode_Region");
            });

            modelBuilder.Entity<Role>(entity =>
            {
                entity.ToTable("Role");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.Name)
                    .HasMaxLength(50)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<Transport>(entity =>
            {
                entity.ToTable("Transport");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.RelaseYear).HasColumnType("date");

                entity.Property(e => e.Vin)
                    .HasMaxLength(17)
                    .IsUnicode(false)
                    .HasColumnName("VIN");

                entity.HasOne(d => d.CategoryNavigation)
                    .WithMany(p => p.Transports)
                    .HasForeignKey(d => d.Category)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Transport_Category");

                entity.HasOne(d => d.ColorNavigation)
                    .WithMany(p => p.Transports)
                    .HasForeignKey(d => d.Color)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Transport_Color");

                entity.HasOne(d => d.DriveTypeNavigation)
                    .WithMany(p => p.Transports)
                    .HasForeignKey(d => d.DriveType)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Transport_DriveType");

                entity.HasOne(d => d.EngineTypeNavigation)
                    .WithMany(p => p.Transports)
                    .HasForeignKey(d => d.EngineType)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Transport_EngineType");

                entity.HasOne(d => d.ModelNavigation)
                    .WithMany(p => p.Transports)
                    .HasForeignKey(d => d.Model)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Transport_Model");

                entity.HasOne(d => d.RegionNavigation)
                    .WithMany(p => p.Transports)
                    .HasForeignKey(d => d.Region)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Transport_Region");
            });

            modelBuilder.Entity<TransportOwnership>(entity =>
            {
                entity.ToTable("TransportOwnership");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.CreatedAt).HasColumnType("date");

                entity.HasOne(d => d.CitizenNavigation)
                    .WithMany(p => p.TransportOwnerships)
                    .HasForeignKey(d => d.Citizen)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_TransportOwnership_Citizen");

                entity.HasOne(d => d.TransportNavigation)
                    .WithMany(p => p.TransportOwnerships)
                    .HasForeignKey(d => d.Transport)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_TransportOwnership_Transport");
            });

            modelBuilder.Entity<TransportPhoto>(entity =>
            {
                entity.ToTable("TransportPhoto");

                entity.Property(e => e.Id).HasColumnName("ID");

                entity.HasOne(d => d.PhotoNavigation)
                    .WithMany(p => p.TransportPhotos)
                    .HasForeignKey(d => d.Photo)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_TransportPhoto_File");

                entity.HasOne(d => d.TransportNavigation)
                    .WithMany(p => p.TransportPhotos)
                    .HasForeignKey(d => d.Transport)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_TransportPhoto_Transport");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
