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

namespace WpfApp4
{
    public partial class HelpContext : DbContext
    {
        public HelpContext()
        {
        }

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

        public virtual DbSet<StatusTask> StatusTasks { get; set; } = null!;
        public virtual DbSet<Task> Tasks { get; set; } = null!;
        public virtual DbSet<User> Users { get; set; } = null!;

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseLazyLoadingProxies();//Ленивая подгрузка навигационных свойств
                optionsBuilder.UseSqlServer("Data Source=(LocalDb)\\MSSQLLocalDB; Initial Catalog=Help;Trusted_Connection=True;");

            }
        }

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

                entity.ToTable("StatusTask");

                entity.Property(e => e.IdstatusTask).HasColumnName("IDStatusTask");

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

            modelBuilder.Entity<Task>(entity =>
            {
                entity.HasKey(e => e.Idtask);

                entity.ToTable("Task");

                entity.Property(e => e.Idtask)
                    .ValueGeneratedNever()
                    .HasColumnName("IDTask");

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

                entity.Property(e => e.IdstatusTask).HasColumnName("IDStatusTask");

                entity.Property(e => e.IduserAccept).HasColumnName("IDUserAccept");

                entity.Property(e => e.IduserCreated).HasColumnName("IDUserCreated");

                entity.Property(e => e.Title).HasMaxLength(50);

                entity.HasOne(d => d.IdstatusTaskNavigation)
                    .WithMany(p => p.Tasks)
                    .HasForeignKey(d => d.IdstatusTask)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Task_StatusTask");

                entity.HasOne(d => d.IduserAcceptNavigation)
                    .WithMany(p => p.TaskIduserAcceptNavigations)
                    .HasForeignKey(d => d.IduserAccept)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Task_User");

                entity.HasOne(d => d.IduserCreatedNavigation)
                    .WithMany(p => p.TaskIduserCreatedNavigations)
                    .HasForeignKey(d => d.IduserCreated)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Task_User1");
            });

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

                entity.ToTable("User");

                entity.Property(e => e.Iduser)
                    .ValueGeneratedNever()
                    .HasColumnName("IDUser");

                entity.Property(e => e.LastName).HasMaxLength(50);

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

                entity.Property(e => e.Surname).HasMaxLength(50);
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
