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

namespace pr13.Models;

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

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

    public virtual DbSet<Course> Courses { get; set; }

    public virtual DbSet<Gender> Genders { get; set; }

    public virtual DbSet<Role> Roles { get; set; }

    public virtual DbSet<Teacher> Teachers { get; set; }

    public virtual DbSet<TeachersCourse> TeachersCourses { get; set; }

    public virtual DbSet<User> Users { 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 http://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseNpgsql("Host=edu.pg.ngknn.local;Port=5432;Database=Smirnov2;Username=43P;Password=444444");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.HasPostgresExtension("pg_catalog", "adminpack");

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

            entity.ToTable("courses");

            entity.Property(e => e.Id)
                .UseIdentityAlwaysColumn()
                .HasColumnName("id");
            entity.Property(e => e.Course1)
                .HasColumnType("character varying")
                .HasColumnName("course");
        });

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

            entity.ToTable("genders");

            entity.Property(e => e.Id)
                .UseIdentityAlwaysColumn()
                .HasColumnName("id");
            entity.Property(e => e.Gender1)
                .HasColumnType("character varying")
                .HasColumnName("gender");
        });

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

            entity.ToTable("roles");

            entity.Property(e => e.IdRole)
                .UseIdentityAlwaysColumn()
                .HasColumnName("id_role");
            entity.Property(e => e.Role1)
                .HasColumnType("character varying")
                .HasColumnName("role");
        });

        modelBuilder.Entity<Teacher>(entity =>
        {
            entity.HasKey(e => e.IdTeacher).HasName("teachers_pk");

            entity.ToTable("teachers");

            entity.Property(e => e.IdTeacher)
                .ValueGeneratedOnAdd()
                .UseIdentityAlwaysColumn()
                .HasColumnName("id_teacher");
            entity.Property(e => e.Birthdate)
                .HasColumnType("timestamp without time zone")
                .HasColumnName("birthdate");
            entity.Property(e => e.Email)
                .HasColumnType("character varying")
                .HasColumnName("email");
            entity.Property(e => e.Expirience).HasColumnName("expirience");
            entity.Property(e => e.IdGender).HasColumnName("id_gender");
            entity.Property(e => e.Name)
                .HasColumnType("character varying")
                .HasColumnName("name");
            entity.Property(e => e.Patronymic)
                .HasColumnType("character varying")
                .HasColumnName("patronymic");
            entity.Property(e => e.Phone)
                .HasColumnType("character varying")
                .HasColumnName("phone");
            entity.Property(e => e.Surname)
                .HasColumnType("character varying")
                .HasColumnName("surname");

            entity.HasOne(d => d.IdGenderNavigation).WithMany(p => p.Teachers)
                .HasForeignKey(d => d.IdGender)
                .HasConstraintName("teachers_fk");

            entity.HasOne(d => d.IdTeacherNavigation).WithOne(p => p.Teacher)
                .HasForeignKey<Teacher>(d => d.IdTeacher)
                .HasConstraintName("teachers_fk1");
        });

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

            entity.ToTable("teachers_courses");

            entity.Property(e => e.Id)
                .UseIdentityAlwaysColumn()
                .HasColumnName("id");
            entity.Property(e => e.Hours).HasColumnName("hours");
            entity.Property(e => e.IdCourse).HasColumnName("id_course");
            entity.Property(e => e.IdTeacher).HasColumnName("id_teacher");

            entity.HasOne(d => d.IdCourseNavigation).WithMany(p => p.TeachersCourses)
                .HasForeignKey(d => d.IdCourse)
                .HasConstraintName("teachers_courses_fk_1");

            entity.HasOne(d => d.IdTeacherNavigation).WithMany(p => p.TeachersCourses)
                .HasForeignKey(d => d.IdTeacher)
                .HasConstraintName("teachers_courses_fk");
        });

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

            entity.ToTable("users");

            entity.Property(e => e.IdUser)
                .UseIdentityAlwaysColumn()
                .HasColumnName("id_user");
            entity.Property(e => e.IdRole).HasColumnName("id_role");
            entity.Property(e => e.Login)
                .HasColumnType("character varying")
                .HasColumnName("login");
            entity.Property(e => e.Password)
                .HasColumnType("character varying")
                .HasColumnName("password");

            entity.HasOne(d => d.IdRoleNavigation).WithMany(p => p.Users)
                .HasForeignKey(d => d.IdRole)
                .HasConstraintName("users_fk");
        });
        modelBuilder.HasSequence("courses_id_seq").HasMax(2147483647L);
        modelBuilder.HasSequence("genders_id_seq").HasMax(2147483647L);
        modelBuilder.HasSequence("roles_id_role_seq").HasMax(2147483647L);
        modelBuilder.HasSequence("teachers_courses_id_seq").HasMax(2147483647L);
        modelBuilder.HasSequence("teachers_id_seq").HasMax(2147483647L);
        modelBuilder.HasSequence("users_id_user_seq").HasMax(2147483647L);

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
