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

namespace WPFYifis2
{
    public partial class gr606_alvviContext : DbContext
    {
        public gr606_alvviContext()
        {
        }

        public gr606_alvviContext(DbContextOptions<gr606_alvviContext> options)
            : base(options)
        {
        }
            
        public virtual DbSet<Jump> Jumps { get; set; } = null!;
        public virtual DbSet<JumpUserList> JumpUserLists { get; set; } = null!;
        public virtual DbSet<Lesson> Lessons { get; set; } = null!;
        public virtual DbSet<Parachute> Parachutes { get; set; } = null!;
        public virtual DbSet<PassportDatum> PassportData { get; set; } = null!;
        public virtual DbSet<Role> Roles { get; set; } = null!;
        public virtual DbSet<TypeLesson> TypeLessons { get; set; } = null!;
        public virtual DbSet<TypeParachute> TypeParachutes { get; set; } = null!;
        public virtual DbSet<User> Users { get; set; } = null!;
        public virtual DbSet<UserList> UserLists { get; set; } = null!;

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseSqlServer("Data source=mssql; Database=gr606_alvvi; Integrated Security=true");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Jump>(entity =>
            {
                entity.HasKey(e => e.IdJump);

                entity.ToTable("Jump");

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

                entity.HasOne(d => d.IdParachuteNavigation)
                    .WithMany(p => p.Jumps)
                    .HasForeignKey(d => d.IdParachute)
                    .HasConstraintName("FK_Jump_Parachute");
            });

            modelBuilder.Entity<JumpUserList>(entity =>
            {
                entity.HasKey(e => e.IdJumpUserList);

                entity.ToTable("JumpUserList");

                entity.HasOne(d => d.IdJumpNavigation)
                    .WithMany(p => p.JumpUserLists)
                    .HasForeignKey(d => d.IdJump)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_JumpUserList_Jump");

                entity.HasOne(d => d.IdUserNavigation)
                    .WithMany(p => p.JumpUserLists)
                    .HasForeignKey(d => d.IdUser)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_JumpUserList_User");
            });

            modelBuilder.Entity<Lesson>(entity =>
            {
                entity.HasKey(e => e.IdLessons);

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

                entity.Property(e => e.LessonsTopic).HasMaxLength(100);

                entity.HasOne(d => d.IdInsrtuctorNavigation)
                    .WithMany(p => p.Lessons)
                    .HasForeignKey(d => d.IdInsrtuctor)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Lessons_User");

                entity.HasOne(d => d.IdTypeLessonsNavigation)
                    .WithMany(p => p.Lessons)
                    .HasForeignKey(d => d.IdTypeLessons)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Lessons_TypeLessons");

                entity.HasOne(d => d.IdUserListNavigation)
                    .WithMany(p => p.Lessons)
                    .HasForeignKey(d => d.IdUserList)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Lessons_UserList");
            });

            modelBuilder.Entity<Parachute>(entity =>
            {
                entity.HasKey(e => e.IdParachute);

                entity.ToTable("Parachute");

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

                entity.HasOne(d => d.IdTypeParachuteNavigation)
                    .WithMany(p => p.Parachutes)
                    .HasForeignKey(d => d.IdTypeParachute)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Parachute_TypeParachute1");
            });

            modelBuilder.Entity<PassportDatum>(entity =>
            {
                entity.HasKey(e => e.IdPassportData);

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

                entity.Property(e => e.Issued).HasMaxLength(150);

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

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

            modelBuilder.Entity<Role>(entity =>
            {
                entity.HasKey(e => e.IdRole);

                entity.ToTable("Role");

                entity.Property(e => e.Role1)
                    .HasMaxLength(50)
                    .HasColumnName("Role");
            });

            modelBuilder.Entity<TypeLesson>(entity =>
            {
                entity.HasKey(e => e.IdTypeLessons);

                entity.Property(e => e.TypeLessons).HasMaxLength(100);
            });

            modelBuilder.Entity<TypeParachute>(entity =>
            {
                entity.HasKey(e => e.IdTypeParachute);

                entity.ToTable("TypeParachute");

                entity.Property(e => e.TypeParachute1)
                    .HasMaxLength(100)
                    .HasColumnName("TypeParachute");
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.HasKey(e => e.IdUser);

                entity.ToTable("User");

                entity.Property(e => e.DateOfBirth).HasMaxLength(100);

                entity.Property(e => e.Email).HasMaxLength(100);

                entity.Property(e => e.Login).HasMaxLength(100);

                entity.Property(e => e.MiddleName).HasMaxLength(100);

                entity.Property(e => e.Name).HasMaxLength(100);

                entity.Property(e => e.Password).HasMaxLength(100);

                entity.Property(e => e.PhoneNumber)
                    .HasMaxLength(12)
                    .IsUnicode(false);

                entity.Property(e => e.Surname).HasMaxLength(100);

                entity.HasOne(d => d.IdPassportDataNavigation)
                    .WithMany(p => p.Users)
                    .HasForeignKey(d => d.IdPassportData)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_User_PassportData");

                entity.HasOne(d => d.IdRoleNavigation)
                    .WithMany(p => p.Users)
                    .HasForeignKey(d => d.IdRole)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_User_Role");
            });

            modelBuilder.Entity<UserList>(entity =>
            {
                entity.HasKey(e => e.IsUserList);

                entity.ToTable("UserList");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
