using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Pomelo.EntityFrameworkCore.MySql.Scaffolding.Internal;

namespace WinFormsApp3.Models;

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

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

    public virtual DbSet<EdIzm> EdIzms { get; set; }

    public virtual DbSet<Material> Materials { get; set; }

    public virtual DbSet<MaterialName> MaterialNames { get; set; }

    public virtual DbSet<MaterialSupplier> MaterialSuppliers { get; set; }

    public virtual DbSet<MaterialType> MaterialTypes { get; set; }

    public virtual DbSet<Supplier> Suppliers { get; set; }

    public virtual DbSet<TypeProduct> TypeProducts { 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 https://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseMySql("server=192.168.201.207;username=pozorisp;password=pozorisp;database=pozorisp_sosn", Microsoft.EntityFrameworkCore.ServerVersion.Parse("5.7.44-mysql"));

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder
            .UseCollation("utf8mb4_unicode_ci")
            .HasCharSet("utf8mb4");

        modelBuilder.Entity<EdIzm>(entity =>
        {
            entity.HasKey(e => e.IdedIzm).HasName("PRIMARY");

            entity.ToTable("ed_izm");

            entity.Property(e => e.IdedIzm)
                .ValueGeneratedNever()
                .HasColumnType("int(11)")
                .HasColumnName("ided_izm");
            entity.Property(e => e.Name).HasMaxLength(45);
        });

        modelBuilder.Entity<Material>(entity =>
        {
            entity.HasKey(e => e.IdMaterials).HasName("PRIMARY");

            entity.Property(e => e.IdMaterials)
                .ValueGeneratedNever()
                .HasColumnType("int(11)")
                .HasColumnName("idMaterials");
            entity.Property(e => e.ColInPack).HasMaxLength(45);
            entity.Property(e => e.IdMaterialSuppliers)
                .HasMaxLength(45)
                .HasColumnName("idMaterial_suppliers");
            entity.Property(e => e.IdMaterialType)
                .HasMaxLength(45)
                .HasColumnName("idMaterial_type");
            entity.Property(e => e.IdedIzm)
                .HasMaxLength(45)
                .HasColumnName("ided_izm");
            entity.Property(e => e.MinCol).HasMaxLength(45);
            entity.Property(e => e.PriceEd).HasMaxLength(45);
            entity.Property(e => e.SkladCol).HasMaxLength(45);
        });

        modelBuilder.Entity<MaterialName>(entity =>
        {
            entity.HasKey(e => e.IdMaterialName).HasName("PRIMARY");

            entity.ToTable("MaterialName");

            entity.Property(e => e.IdMaterialName)
                .ValueGeneratedNever()
                .HasColumnType("int(11)")
                .HasColumnName("idMaterialName");
            entity.Property(e => e.MaterialName1)
                .HasMaxLength(45)
                .HasColumnName("MaterialName");
        });

        modelBuilder.Entity<MaterialSupplier>(entity =>
        {
            entity.HasKey(e => e.IdMaterialSuppliers).HasName("PRIMARY");

            entity.ToTable("Material_suppliers");

            entity.HasIndex(e => e.IdMaterialName, "MATERIALNAME_idx");

            entity.HasIndex(e => e.IdSupplier, "SUPP_idx");

            entity.Property(e => e.IdMaterialSuppliers)
                .ValueGeneratedNever()
                .HasColumnType("int(11)")
                .HasColumnName("idMaterial_suppliers");
            entity.Property(e => e.IdMaterialName)
                .HasColumnType("int(11)")
                .HasColumnName("idMaterialName");
            entity.Property(e => e.IdSupplier)
                .HasColumnType("int(11)")
                .HasColumnName("idSupplier");

            entity.HasOne(d => d.IdMaterialNameNavigation).WithMany(p => p.MaterialSuppliers)
                .HasForeignKey(d => d.IdMaterialName)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("MATERIALNAME");

            entity.HasOne(d => d.IdSupplierNavigation).WithMany(p => p.MaterialSuppliers)
                .HasForeignKey(d => d.IdSupplier)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("SUPP");
        });

        modelBuilder.Entity<MaterialType>(entity =>
        {
            entity.HasKey(e => e.IdMaterialType).HasName("PRIMARY");

            entity.ToTable("Material_type");

            entity.Property(e => e.IdMaterialType)
                .ValueGeneratedNever()
                .HasColumnType("int(11)")
                .HasColumnName("idMaterial_type");
            entity.Property(e => e.Percent).HasMaxLength(45);
            entity.Property(e => e.TypeMaterial).HasMaxLength(45);
        });

        modelBuilder.Entity<Supplier>(entity =>
        {
            entity.HasKey(e => e.IdPostav).HasName("PRIMARY");

            entity.ToTable("Supplier");

            entity.Property(e => e.IdPostav)
                .ValueGeneratedNever()
                .HasColumnType("int(11)")
                .HasColumnName("idPostav");
            entity.Property(e => e.Inn)
                .HasColumnType("int(10)")
                .HasColumnName("INN");
            entity.Property(e => e.Name).HasMaxLength(45);
            entity.Property(e => e.Rate).HasColumnType("int(2)");
            entity.Property(e => e.Type).HasMaxLength(45);
        });

        modelBuilder.Entity<TypeProduct>(entity =>
        {
            entity.HasKey(e => e.IdTypeProduct).HasName("PRIMARY");

            entity.ToTable("TypeProduct");

            entity.Property(e => e.IdTypeProduct)
                .ValueGeneratedNever()
                .HasColumnType("int(11)")
                .HasColumnName("idTypeProduct");
            entity.Property(e => e.TypeKoof).HasColumnType("int(11)");
            entity.Property(e => e.TypeName).HasMaxLength(45);
        });

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

            entity.ToTable("user");

            entity.Property(e => e.Iduser)
                .ValueGeneratedNever()
                .HasColumnType("int(11)")
                .HasColumnName("iduser");
            entity.Property(e => e.Password)
                .HasMaxLength(45)
                .HasColumnName("password");
            entity.Property(e => e.Role)
                .HasMaxLength(45)
                .HasColumnName("role");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
