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

namespace demko6.Models;

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

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

    public virtual DbSet<Client> Clients { get; set; }

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

    public virtual DbSet<EmployeeService> EmployeeServices { get; set; }

    public virtual DbSet<FClient> FClients { get; set; }

    public virtual DbSet<Order> Orders { get; set; }

    public virtual DbSet<OrderService> OrderServices { get; set; }

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

    public virtual DbSet<Service> Services { get; set; }

    public virtual DbSet<UrClient> UrClients { 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=demko_nejykov;;Username=demko_nejykov;;Password=demko_nejykov;Port=5448");

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

            entity.ToTable("clients");

            entity.HasIndex(e => e.ClientCode, "unique_client_code").IsUnique();

            entity.HasIndex(e => e.CodeFClient, "unique_code_f_client").IsUnique();

            entity.HasIndex(e => e.CodeUrClient, "unique_code_ur_client").IsUnique();

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.ClientCode)
                .HasMaxLength(50)
                .HasColumnName("client_code");
            entity.Property(e => e.CodeFClient)
                .HasMaxLength(50)
                .HasColumnName("code_f_client");
            entity.Property(e => e.CodeUrClient)
                .HasMaxLength(50)
                .HasColumnName("code_ur_client");
            entity.Property(e => e.UrOrNo).HasColumnName("ur_or_no");

            entity.HasOne(d => d.CodeFClientNavigation).WithOne(p => p.Client)
                .HasPrincipalKey<FClient>(p => p.Code)
                .HasForeignKey<Client>(d => d.CodeFClient)
                .OnDelete(DeleteBehavior.SetNull)
                .HasConstraintName("fk_orders_code_f_client");

            entity.HasOne(d => d.CodeUrClientNavigation).WithOne(p => p.Client)
                .HasPrincipalKey<UrClient>(p => p.Code)
                .HasForeignKey<Client>(d => d.CodeUrClient)
                .OnDelete(DeleteBehavior.SetNull)
                .HasConstraintName("fk_orders_code_ur_client");
        });

        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.LastLogin)
                .HasColumnType("timestamp without time zone")
                .HasColumnName("last_login");
            entity.Property(e => e.Login)
                .HasMaxLength(255)
                .HasColumnName("login");
            entity.Property(e => e.Name)
                .HasMaxLength(255)
                .HasColumnName("name");
            entity.Property(e => e.Password)
                .HasMaxLength(255)
                .HasColumnName("password");
            entity.Property(e => e.RoleId).HasColumnName("role_id");

            entity.HasOne(d => d.Role).WithMany(p => p.Employees)
                .HasForeignKey(d => d.RoleId)
                .HasConstraintName("employees_role_id_fkey");
        });

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

            entity.ToTable("employee_service");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.EmployeeId).HasColumnName("employee_id");
            entity.Property(e => e.ServiceId).HasColumnName("service_id");

            entity.HasOne(d => d.Employee).WithMany(p => p.EmployeeServices)
                .HasForeignKey(d => d.EmployeeId)
                .HasConstraintName("employee_service_employee_id_fkey");

            entity.HasOne(d => d.Service).WithMany(p => p.EmployeeServices)
                .HasForeignKey(d => d.ServiceId)
                .HasConstraintName("employee_service_service_id_fkey");
        });

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

            entity.ToTable("f_client");

            entity.HasIndex(e => e.Code, "f_client_code_unique").IsUnique();

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Address)
                .HasMaxLength(512)
                .HasColumnName("address");
            entity.Property(e => e.Birthday).HasColumnName("birthday");
            entity.Property(e => e.Code)
                .HasMaxLength(50)
                .HasColumnName("code");
            entity.Property(e => e.Email)
                .HasMaxLength(255)
                .HasColumnName("email");
            entity.Property(e => e.Name)
                .HasMaxLength(255)
                .HasColumnName("name");
            entity.Property(e => e.Passport)
                .HasMaxLength(255)
                .HasColumnName("passport");
            entity.Property(e => e.Password)
                .HasMaxLength(255)
                .HasColumnName("password");
        });

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

            entity.ToTable("orders");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.ClientCode)
                .HasMaxLength(50)
                .HasColumnName("client_code");
            entity.Property(e => e.CreatedAt)
                .HasColumnType("timestamp without time zone")
                .HasColumnName("created_at");
            entity.Property(e => e.EmployeeId).HasColumnName("employee_id");
            entity.Property(e => e.OrderNumber)
                .HasMaxLength(255)
                .HasColumnName("order_number");
            entity.Property(e => e.Orederclosetime)
                .HasColumnType("timestamp without time zone")
                .HasColumnName("orederclosetime");
            entity.Property(e => e.Prokattime).HasColumnName("prokattime");
            entity.Property(e => e.Status)
                .HasMaxLength(255)
                .HasColumnName("status");

            entity.HasOne(d => d.ClientCodeNavigation).WithMany(p => p.Orders)
                .HasPrincipalKey(p => p.ClientCode)
                .HasForeignKey(d => d.ClientCode)
                .OnDelete(DeleteBehavior.SetNull)
                .HasConstraintName("fk_orders_client_code");

            entity.HasOne(d => d.Employee).WithMany(p => p.Orders)
                .HasForeignKey(d => d.EmployeeId)
                .HasConstraintName("orders_employee_id_fkey");
        });

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

            entity.ToTable("order_service");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.OrderId).HasColumnName("order_id");
            entity.Property(e => e.ServiceId).HasColumnName("service_id");

            entity.HasOne(d => d.Order).WithMany(p => p.OrderServices)
                .HasForeignKey(d => d.OrderId)
                .HasConstraintName("order_service_order_id_fkey");

            entity.HasOne(d => d.Service).WithMany(p => p.OrderServices)
                .HasForeignKey(d => d.ServiceId)
                .HasConstraintName("order_service_service_id_fkey");
        });

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

            entity.ToTable("role");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Name)
                .HasMaxLength(255)
                .HasColumnName("name");
        });

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

            entity.ToTable("services");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Code)
                .HasMaxLength(255)
                .HasColumnName("code");
            entity.Property(e => e.Cost)
                .HasMaxLength(255)
                .HasColumnName("cost");
            entity.Property(e => e.CostZao).HasColumnName("cost_zao");
            entity.Property(e => e.DeviationUnit)
                .HasMaxLength(20)
                .HasDefaultValueSql("''::character varying")
                .HasColumnName("deviation_unit");
            entity.Property(e => e.DeviationValue)
                .HasPrecision(10, 4)
                .HasColumnName("deviation_value");
            entity.Property(e => e.DueDate).HasColumnName("due_date");
            entity.Property(e => e.Name)
                .HasMaxLength(255)
                .HasColumnName("name");
        });

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

            entity.ToTable("ur_client");

            entity.HasIndex(e => e.Code, "ur_client_code_unique").IsUnique();

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Adress)
                .HasMaxLength(255)
                .HasColumnName("adress");
            entity.Property(e => e.Bik)
                .HasMaxLength(9)
                .HasColumnName("bik");
            entity.Property(e => e.Code)
                .HasMaxLength(50)
                .HasColumnName("code");
            entity.Property(e => e.Email)
                .HasMaxLength(255)
                .HasColumnName("email");
            entity.Property(e => e.FioKontakt)
                .HasMaxLength(255)
                .HasColumnName("fio_kontakt");
            entity.Property(e => e.FioRuk)
                .HasMaxLength(255)
                .HasColumnName("fio_ruk");
            entity.Property(e => e.Inn)
                .HasMaxLength(12)
                .HasColumnName("inn");
            entity.Property(e => e.Name)
                .HasMaxLength(255)
                .HasColumnName("name");
            entity.Property(e => e.Password)
                .HasMaxLength(255)
                .HasColumnName("password");
            entity.Property(e => e.Pc)
                .HasMaxLength(20)
                .HasColumnName("pc");
            entity.Property(e => e.PhoneKontakt)
                .HasMaxLength(20)
                .HasColumnName("phone_kontakt");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
