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

namespace Entidades;

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

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

    public virtual DbSet<Canon> Canons { get; set; }

    public virtual DbSet<Cliente> Clientes { get; set; }

    public virtual DbSet<Contrato> Contratos { get; set; }

    public virtual DbSet<Defecto> Defectos { get; set; }

    public virtual DbSet<Estadodefecto> Estadodefectos { get; set; }

    public virtual DbSet<Estadoventum> Estadoventa { get; set; }

    public virtual DbSet<Garante> Garantes { get; set; }

    public virtual DbSet<Grupo> Grupos { get; set; }

    public virtual DbSet<Permiso> Permisos { get; set; }

    public virtual DbSet<Propiedade> Propiedades { get; set; }

    public virtual DbSet<Recibo> Recibos { get; set; }

    public virtual DbSet<Usuario> Usuarios { get; set; }

    public virtual DbSet<Venta> Ventas { 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=fedesrv.ddns.net;Port=30006;Database=AlquilaFacil;Uid=AlquilaFacil;Pwd=.n@9c2ve*0,b1ETv].Kipa/~pR~V;Connection Timeout=5;SslMode=none");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Canon>(entity =>
        {
            entity.HasKey(e => e.id).HasName("PRIMARY");

            entity.ToTable("Canon");

            entity.HasIndex(e => e.idrecibo, "FK_CAN_REC");

            entity.Property(e => e.id).HasColumnType("bigint(20)");
            entity.Property(e => e.fecha).HasColumnType("date");
            entity.Property(e => e.idrecibo).HasColumnType("bigint(20)");
            entity.Property(e => e.monto).HasPrecision(12);
            entity.Property(e => e.pagado).HasColumnType("bit(1)");

            entity.HasOne(d => d.idreciboNavigation).WithMany(p => p.Canons)
                .HasForeignKey(d => d.idrecibo)
                .OnDelete(DeleteBehavior.Restrict)
                .HasConstraintName("FK_CAN_REC");
        });

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

            entity.HasIndex(e => e.idusuario, "FK_PROP_USU");

            entity.Property(e => e.dni).HasColumnType("bigint(20)");
            entity.Property(e => e.apellido).HasMaxLength(20);
            entity.Property(e => e.celular).HasMaxLength(40);
            entity.Property(e => e.domicilio).HasMaxLength(40);
            entity.Property(e => e.idusuario).HasColumnType("int(11)");
            entity.Property(e => e.nombre).HasMaxLength(20);

            entity.HasOne(d => d.idusuarioNavigation).WithMany(p => p.Clientes)
                .HasForeignKey(d => d.idusuario)
                .OnDelete(DeleteBehavior.Restrict)
                .HasConstraintName("FK_PROP_USU");
        });

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

            entity.HasIndex(e => e.dniinquilino, "FK_CON_INQ");

            entity.HasIndex(e => e.idpropiedad, "FK_CON_PROP");

            entity.HasIndex(e => e.dnipropietario, "FK_CON_PROPI");

            entity.HasIndex(e => e.idventa, "FK_CON_VEN");

            entity.Property(e => e.id).HasColumnType("bigint(20)");
            entity.Property(e => e.cantgarantemin).HasColumnType("int(11)");
            entity.Property(e => e.dniinquilino).HasColumnType("bigint(20)");
            entity.Property(e => e.dnipropietario).HasColumnType("bigint(20)");
            entity.Property(e => e.fechainicio).HasColumnType("date");
            entity.Property(e => e.idpropiedad).HasColumnType("int(11)");
            entity.Property(e => e.idventa).HasColumnType("bigint(20)");
            entity.Property(e => e.indiceactualizacion).HasPrecision(8);
            entity.Property(e => e.monto).HasPrecision(12);
            entity.Property(e => e.tieneopcionventa).HasColumnType("bit(1)");

            entity.HasOne(d => d.dniinquilinoNavigation).WithMany(p => p.ContratodniinquilinoNavigations)
                .HasForeignKey(d => d.dniinquilino)
                .OnDelete(DeleteBehavior.Restrict)
                .HasConstraintName("FK_CON_INQ");

            entity.HasOne(d => d.dnipropietarioNavigation).WithMany(p => p.ContratodnipropietarioNavigations)
                .HasForeignKey(d => d.dnipropietario)
                .OnDelete(DeleteBehavior.Restrict)
                .HasConstraintName("FK_CON_PROPI");

            entity.HasOne(d => d.idpropiedadNavigation).WithMany(p => p.Contratos)
                .HasForeignKey(d => d.idpropiedad)
                .OnDelete(DeleteBehavior.Restrict)
                .HasConstraintName("FK_CON_PROP");

            entity.HasOne(d => d.idventaNavigation).WithMany(p => p.Contratos)
                .HasForeignKey(d => d.idventa)
                .OnDelete(DeleteBehavior.Restrict)
                .HasConstraintName("FK_CON_VEN");

            entity.HasMany(d => d.idcanons).WithMany(p => p.idcontratos)
                .UsingEntity<Dictionary<string, object>>(
                    "contrato_canon",
                    r => r.HasOne<Canon>().WithMany()
                        .HasForeignKey("idcanon")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("FK_CONCAN_CAN"),
                    l => l.HasOne<Contrato>().WithMany()
                        .HasForeignKey("idcontrato")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("FK_CONCAN_CON"),
                    j =>
                    {
                        j.HasKey("idcontrato", "idcanon").HasName("PRIMARY");
                        j.ToTable("contrato_canon");
                        j.HasIndex(new[] { "idcanon" }, "FK_CONCAN_CAN");
                        j.IndexerProperty<long>("idcontrato").HasColumnType("bigint(20)");
                        j.IndexerProperty<long>("idcanon").HasColumnType("bigint(20)");
                    });
        });

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

            entity.ToTable("Defecto");

            entity.HasIndex(e => e.idcontrato, "FK_DEF_CON");

            entity.HasIndex(e => e.idestado, "FK_DEF_EST");

            entity.Property(e => e.id).HasColumnType("bigint(20)");
            entity.Property(e => e.costo).HasPrecision(12);
            entity.Property(e => e.descripcion).HasMaxLength(40);
            entity.Property(e => e.idcontrato).HasColumnType("bigint(20)");
            entity.Property(e => e.idestado).HasColumnType("int(11)");
            entity.Property(e => e.pagainquilino).HasColumnType("bit(1)");

            entity.HasOne(d => d.idcontratoNavigation).WithMany(p => p.Defectos)
                .HasForeignKey(d => d.idcontrato)
                .OnDelete(DeleteBehavior.Restrict)
                .HasConstraintName("FK_DEF_CON");

            entity.HasOne(d => d.idestadoNavigation).WithMany(p => p.Defectos)
                .HasForeignKey(d => d.idestado)
                .OnDelete(DeleteBehavior.Restrict)
                .HasConstraintName("FK_DEF_EST");
        });

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

            entity.ToTable("Estadodefecto");

            entity.Property(e => e.id).HasColumnType("int(11)");
            entity.Property(e => e.descipcion).HasMaxLength(20);
        });

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

            entity.Property(e => e.id).HasColumnType("int(11)");
            entity.Property(e => e.descripcion).HasMaxLength(15);
        });

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

            entity.Property(e => e.dni).HasColumnType("bigint(20)");
            entity.Property(e => e.apellido).HasMaxLength(20);
            entity.Property(e => e.celular).HasMaxLength(40);
            entity.Property(e => e.domicilio).HasMaxLength(40);
            entity.Property(e => e.domiciliolaboral).HasMaxLength(40);
            entity.Property(e => e.nombre).HasMaxLength(20);

            entity.HasMany(d => d.idcontratos).WithMany(p => p.dnigarantes)
                .UsingEntity<Dictionary<string, object>>(
                    "contrato_garante",
                    r => r.HasOne<Contrato>().WithMany()
                        .HasForeignKey("idcontrato")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("FK_CONGAR_CON"),
                    l => l.HasOne<Garante>().WithMany()
                        .HasForeignKey("dnigarante")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("FK_CONGAR_GAR"),
                    j =>
                    {
                        j.HasKey("dnigarante", "idcontrato").HasName("PRIMARY");
                        j.ToTable("contrato_garantes");
                        j.HasIndex(new[] { "idcontrato" }, "FK_CONGAR_CON");
                        j.IndexerProperty<long>("dnigarante").HasColumnType("bigint(20)");
                        j.IndexerProperty<long>("idcontrato").HasColumnType("bigint(20)");
                    });
        });

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

            entity.Property(e => e.id).HasColumnType("int(11)");
            entity.Property(e => e.nombre).HasMaxLength(12);
        });

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

            entity.Property(e => e.id).HasColumnType("int(11)");
            entity.Property(e => e.descripcion).HasMaxLength(15);

            entity.HasMany(d => d.idgrupos).WithMany(p => p.idpermisos)
                .UsingEntity<Dictionary<string, object>>(
                    "grupo_Permiso",
                    r => r.HasOne<Grupo>().WithMany()
                        .HasForeignKey("idgrupo")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("FK_GRU2"),
                    l => l.HasOne<Permiso>().WithMany()
                        .HasForeignKey("idpermiso")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("FK_PER2"),
                    j =>
                    {
                        j.HasKey("idpermiso", "idgrupo").HasName("PRIMARY");
                        j.ToTable("grupo_Permisos");
                        j.HasIndex(new[] { "idgrupo" }, "FK_GRU2");
                        j.IndexerProperty<int>("idpermiso").HasColumnType("int(11)");
                        j.IndexerProperty<int>("idgrupo").HasColumnType("int(11)");
                    });
        });

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

            entity.HasIndex(e => e.dnipropietario, "FK_PROP_PROPI");

            entity.Property(e => e.id).HasColumnType("int(11)");
            entity.Property(e => e.canthabitaciones).HasColumnType("int(11)");
            entity.Property(e => e.dnipropietario).HasColumnType("bigint(20)");
            entity.Property(e => e.letra)
                .HasMaxLength(1)
                .IsFixedLength();
            entity.Property(e => e.piso).HasColumnType("int(11)");
            entity.Property(e => e.ubicacion).HasMaxLength(40);

            entity.HasOne(d => d.dnipropietarioNavigation).WithMany(p => p.Propiedades)
                .HasForeignKey(d => d.dnipropietario)
                .OnDelete(DeleteBehavior.Restrict)
                .HasConstraintName("FK_PROP_PROPI");
        });

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

            entity.ToTable("Recibo");

            entity.Property(e => e.id).HasColumnType("bigint(20)");
            entity.Property(e => e.fecha).HasColumnType("date");
            entity.Property(e => e.monto).HasPrecision(12);
        });

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

            entity.Property(e => e.id).HasColumnType("int(11)");
            entity.Property(e => e.contraseña).HasMaxLength(128);
            entity.Property(e => e.email).HasMaxLength(50);
            entity.Property(e => e.token).HasColumnType("json");

            entity.HasMany(d => d.idgrupos).WithMany(p => p.idusuarios)
                .UsingEntity<Dictionary<string, object>>(
                    "usuario_Grupo",
                    r => r.HasOne<Grupo>().WithMany()
                        .HasForeignKey("idgrupo")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("FK_GRU"),
                    l => l.HasOne<Usuario>().WithMany()
                        .HasForeignKey("idusuario")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("FK_USU"),
                    j =>
                    {
                        j.HasKey("idusuario", "idgrupo").HasName("PRIMARY");
                        j.ToTable("usuario_Grupos");
                        j.HasIndex(new[] { "idgrupo" }, "FK_GRU");
                        j.IndexerProperty<int>("idusuario").HasColumnType("int(11)");
                        j.IndexerProperty<int>("idgrupo").HasColumnType("int(11)");
                    });
        });

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

            entity.HasIndex(e => e.idestado, "FK_VEN_EST");

            entity.HasIndex(e => e.idprop_old, "FK_VEN_PROL");

            entity.HasIndex(e => e.idprop_new, "FK_VEN_PRON");

            entity.HasIndex(e => e.idpropiedad, "FK_VEN_PROP");

            entity.Property(e => e.id).HasColumnType("bigint(20)");
            entity.Property(e => e.fechafinal).HasColumnType("date");
            entity.Property(e => e.fechainicio).HasColumnType("date");
            entity.Property(e => e.idestado).HasColumnType("int(11)");
            entity.Property(e => e.idprop_new).HasColumnType("bigint(20)");
            entity.Property(e => e.idprop_old).HasColumnType("bigint(20)");
            entity.Property(e => e.idpropiedad).HasColumnType("int(11)");
            entity.Property(e => e.monto).HasPrecision(12);

            entity.HasOne(d => d.idestadoNavigation).WithMany(p => p.Venta)
                .HasForeignKey(d => d.idestado)
                .OnDelete(DeleteBehavior.Restrict)
                .HasConstraintName("FK_VEN_EST");

            entity.HasOne(d => d.idprop_newNavigation).WithMany(p => p.Ventaidprop_newNavigations)
                .HasForeignKey(d => d.idprop_new)
                .OnDelete(DeleteBehavior.Restrict)
                .HasConstraintName("FK_VEN_PRON");

            entity.HasOne(d => d.idprop_oldNavigation).WithMany(p => p.Ventaidprop_oldNavigations)
                .HasForeignKey(d => d.idprop_old)
                .OnDelete(DeleteBehavior.Restrict)
                .HasConstraintName("FK_VEN_PROL");

            entity.HasOne(d => d.idpropiedadNavigation).WithMany(p => p.Venta)
                .HasForeignKey(d => d.idpropiedad)
                .OnDelete(DeleteBehavior.Restrict)
                .HasConstraintName("FK_VEN_PROP");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
