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

namespace demko_term.Models;

public partial class DemoCourseworkContext : DbContext
{
    public DemoCourseworkContext()
    {
    }

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

    public virtual DbSet<Applicant> Applicants { get; set; }

    public virtual DbSet<Employee> Employees { get; set; }

    public virtual DbSet<EmployeesHistory> EmployeesHistories { get; set; }

    public virtual DbSet<Position> Positions { get; set; }

    public virtual DbSet<Specialty> Specialties { get; set; }

    public virtual DbSet<Statement> Statements { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#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 https://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseNpgsql("Host=localhost;Database=demo_coursework;;Username=demo_coursework;;Password=demo_coursework;Port=5446");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Applicant>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("applicants_pkey");

            entity.ToTable("applicants");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Address)
                .HasMaxLength(255)
                .HasColumnName("address");
            entity.Property(e => e.Code).HasColumnName("code");
            entity.Property(e => e.Date)
                .HasColumnType("timestamp without time zone")
                .HasColumnName("date");
            entity.Property(e => e.Email)
                .HasMaxLength(255)
                .HasColumnName("email");
            entity.Property(e => e.Firstname)
                .HasMaxLength(100)
                .HasColumnName("firstname");
            entity.Property(e => e.Lastname)
                .HasMaxLength(100)
                .HasColumnName("lastname");
            entity.Property(e => e.Passport)
                .HasMaxLength(10)
                .HasColumnName("passport");
            entity.Property(e => e.Patronymic)
                .HasMaxLength(100)
                .HasColumnName("patronymic");
            entity.Property(e => e.Phone)
                .HasMaxLength(20)
                .HasColumnName("phone");
        });

        modelBuilder.Entity<Employee>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("employees_pkey");

            entity.ToTable("employees");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Firstname)
                .HasMaxLength(100)
                .HasColumnName("firstname");
            entity.Property(e => e.Lastname)
                .HasMaxLength(100)
                .HasColumnName("lastname");
            entity.Property(e => e.Login)
                .HasMaxLength(100)
                .HasColumnName("login");
            entity.Property(e => e.Logo)
                .HasMaxLength(250)
                .HasColumnName("logo");
            entity.Property(e => e.Password)
                .HasMaxLength(100)
                .HasColumnName("password");
            entity.Property(e => e.Patronymic)
                .HasMaxLength(100)
                .HasColumnName("patronymic");
            entity.Property(e => e.PositionId).HasColumnName("position_id");

            entity.HasOne(d => d.Position).WithMany(p => p.Employees)
                .HasForeignKey(d => d.PositionId)
                .OnDelete(DeleteBehavior.Cascade)
                .HasConstraintName("employees_position_id_fkey");
        });

        modelBuilder.Entity<EmployeesHistory>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("employees_history_pkey");

            entity.ToTable("employees_history");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.EmployeeId).HasColumnName("employee_id");
            entity.Property(e => e.LastLogin)
                .HasColumnType("timestamp without time zone")
                .HasColumnName("last_login");
            entity.Property(e => e.SuccessLogin).HasColumnName("success_login");

            entity.HasOne(d => d.Employee).WithMany(p => p.EmployeesHistories)
                .HasForeignKey(d => d.EmployeeId)
                .OnDelete(DeleteBehavior.Cascade)
                .HasConstraintName("employees_history_employee_id_fkey");
        });

        modelBuilder.Entity<Position>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("positions_pkey");

            entity.ToTable("positions");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Title)
                .HasMaxLength(100)
                .HasColumnName("title");
        });

        modelBuilder.Entity<Specialty>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("specialties_pkey");

            entity.ToTable("specialties");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Code)
                .HasMaxLength(10)
                .HasColumnName("code");
            entity.Property(e => e.Cost).HasColumnName("cost");
            entity.Property(e => e.EducationForm)
                .HasMaxLength(10)
                .HasColumnName("education_form");
            entity.Property(e => e.Places).HasColumnName("places");
            entity.Property(e => e.Title)
                .HasMaxLength(100)
                .HasColumnName("title");
        });

        modelBuilder.Entity<Statement>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("statements_pkey");

            entity.ToTable("statements");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.ApplicantCode).HasColumnName("applicant_code");
            entity.Property(e => e.ApplicantSpeciality).HasColumnName("applicant_speciality");
            entity.Property(e => e.Diploma).HasColumnName("diploma");
            entity.Property(e => e.Passport).HasColumnName("passport");
            entity.Property(e => e.PersonalNumber)
                .HasMaxLength(100)
                .HasColumnName("personal_number");
            entity.Property(e => e.Points).HasColumnName("points");
            entity.Property(e => e.SubmissionDate).HasColumnName("submission_date");
            entity.Property(e => e.SubmissionTime).HasColumnName("submission_time");

            entity.HasOne(d => d.ApplicantCodeNavigation).WithMany(p => p.Statements)
                .HasForeignKey(d => d.ApplicantCode)
                .OnDelete(DeleteBehavior.Cascade)
                .HasConstraintName("statements_applicant_code_fkey");

            entity.HasOne(d => d.ApplicantSpecialityNavigation).WithMany(p => p.Statements)
                .HasForeignKey(d => d.ApplicantSpeciality)
                .OnDelete(DeleteBehavior.Cascade)
                .HasConstraintName("statements_applicant_speciality_fkey");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
