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

namespace Models.Models;

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

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

    public virtual DbSet<PhOhArcadocumentType> PhOhArcadocumentTypes { get; set; }

    public virtual DbSet<PhOhArcataxType> PhOhArcataxTypes { get; set; }

    public virtual DbSet<PhOhExchangeRateHistory> PhOhExchangeRateHistories { get; set; }

    public virtual DbSet<PhOhTaxCondition> PhOhTaxConditions { get; set; }

    public virtual DbSet<PhOhTicket> PhOhTickets { get; set; }

    public virtual DbSet<PhSAccountType> PhSAccountTypes { get; set; }

    public virtual DbSet<PhSAdjustmentReason> PhSAdjustmentReasons { get; set; }

    public virtual DbSet<PhSBusinessUnit> PhSBusinessUnits { get; set; }

    public virtual DbSet<PhSCustomer> PhSCustomers { get; set; }

    public virtual DbSet<PhSCustomerAddress> PhSCustomerAddresses { get; set; }

    public virtual DbSet<PhSCustomerDocument> PhSCustomerDocuments { get; set; }

    public virtual DbSet<PhSDocumentType> PhSDocumentTypes { get; set; }

    public virtual DbSet<PhSFormSeries> PhSFormSeries { get; set; }

    public virtual DbSet<PhSFormSeriesNextNumber> PhSFormSeriesNextNumbers { get; set; }

    public virtual DbSet<PhSFormType> PhSFormTypes { get; set; }

    public virtual DbSet<PhSInstitution> PhSInstitutions { get; set; }

    public virtual DbSet<PhSPatient> PhSPatients { get; set; }

    public virtual DbSet<PhSPeopleGroup> PhSPeopleGroups { get; set; }

    public virtual DbSet<PhSPerson> PhSPeople { get; set; }

    public virtual DbSet<PhSProduct> PhSProducts { get; set; }

    public virtual DbSet<PhSProductCategory> PhSProductCategories { get; set; }

    public virtual DbSet<PhSProfessional> PhSProfessionals { get; set; }

    public virtual DbSet<PhSProfessionalSpecialty> PhSProfessionalSpecialties { get; set; }

    public virtual DbSet<PhSQuoteAdjustment> PhSQuoteAdjustments { get; set; }

    public virtual DbSet<PhSQuoteDetail> PhSQuoteDetails { get; set; }

    public virtual DbSet<PhSQuoteHeader> PhSQuoteHeaders { get; set; }

    public virtual DbSet<PhSQuoteRole> PhSQuoteRoles { get; set; }

    public virtual DbSet<PhSQuoteTaxis> PhSQuoteTaxes { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    #region VERSION DOCKER
    {
        if (!optionsBuilder.IsConfigured)
        {
            // Dejarlo vacío para usar la configuración externa desde Program.cs o Startup.cs
        }
    }
    #endregion
    //=> optionsBuilder.UseSqlServer("data source=srv01.saludlab.com.ar,39458;initial catalog=phronCare_OperationsHub;User ID=sa;Password=HS|s[~xxQzTo/n>9jO;encrypt=False;trustServerCertificate=True;MultipleActiveResultSets=True");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.UseCollation("Modern_Spanish_CI_AS");

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

            entity.ToTable("PhOH_ARCADocumentTypes", tb => tb.HasComment("Catálogo oficial de tipos de comprobantes AFIP."));

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasColumnName("id");
            entity.Property(e => e.Code)
                .HasMaxLength(3)
                .IsUnicode(false)
                .IsFixedLength()
                .HasColumnName("code");
            entity.Property(e => e.Description)
                .HasMaxLength(255)
                .HasColumnName("description");
            entity.Property(e => e.Isactive)
                .HasDefaultValue(true)
                .HasColumnName("isactive");
            entity.Property(e => e.Letter)
                .HasMaxLength(1)
                .IsUnicode(false)
                .IsFixedLength()
                .HasColumnName("letter");
        });

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

            entity.ToTable("PhOH_ARCATaxTypes", tb => tb.HasComment("Tabla de referencia de tipos de impuestos según AFIP para operaciones de venta."));

            entity.Property(e => e.Id)
                .HasComment("Identificador único del impuesto.")
                .HasColumnName("id");
            entity.Property(e => e.CreatedAt)
                .HasDefaultValueSql("(getdate())")
                .HasComment("Fecha de creación del registro.")
                .HasColumnType("datetime")
                .HasColumnName("created_at");
            entity.Property(e => e.Description)
                .HasMaxLength(100)
                .IsUnicode(false)
                .HasComment("Descripción del impuesto.")
                .HasColumnName("description");
            entity.Property(e => e.IsActive)
                .HasDefaultValue(true)
                .HasComment("Indica si el impuesto está activo (1) o inactivo (0).")
                .HasColumnName("is_active");
            entity.Property(e => e.ModifiedAt)
                .HasComment("Fecha de última modificación del registro.")
                .HasColumnType("datetime")
                .HasColumnName("modified_at");
            entity.Property(e => e.TaxCode)
                .HasComment("Código oficial del impuesto según AFIP.")
                .HasColumnName("tax_code");
            entity.Property(e => e.Taxrate)
                .HasComment("Porcentaje de la alícuota aplicable al impuesto, expresado como un valor decimal. Una alícuota del 21%, se debe almacenar el valor 21.00")
                .HasColumnType("decimal(18, 0)")
                .HasColumnName("taxrate");
        });

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

            entity.ToTable("PhOH_ExchangeRateHistory", tb => tb.HasComment("Histórico de cotizaciones diarias del dólar oficial del BCRA"));

            entity.HasIndex(e => e.Ratedate, "UQ__PhOH_Exc__81B17E87D8FDABB7").IsUnique();

            entity.Property(e => e.Id)
                .HasComment("Clave primaria autonumérica")
                .HasColumnName("id");
            entity.Property(e => e.Createdat)
                .HasDefaultValueSql("(sysutcdatetime())")
                .HasComment("Fecha y hora en que se guardó el registro")
                .HasColumnName("createdat");
            entity.Property(e => e.Purchaserate)
                .HasComment("Tasa de compra del dólar oficial")
                .HasColumnType("decimal(18, 6)")
                .HasColumnName("purchaserate");
            entity.Property(e => e.Ratedate)
                .HasComment("Fecha de la cotización (por ejemplo, 2025-05-06)")
                .HasColumnName("ratedate");
            entity.Property(e => e.Salerate)
                .HasComment("Tasa de venta del dólar oficial")
                .HasColumnType("decimal(18, 6)")
                .HasColumnName("salerate");
            entity.Property(e => e.Source)
                .HasMaxLength(100)
                .IsUnicode(false)
                .HasDefaultValue("BCRA")
                .HasComment("Origen del dato (por ejemplo, BCRA, Blue, MEP, etc.)")
                .HasColumnName("source");
        });

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

            entity.ToTable("PhOH_Tax_Conditions");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.CmpClase)
                .HasMaxLength(10)
                .HasColumnName("cmp_clase");
            entity.Property(e => e.Description)
                .HasMaxLength(100)
                .HasColumnName("description");
        });

        modelBuilder.Entity<PhOhTicket>(entity =>
        {
            entity.HasKey(e => e.TicketId).HasName("PK__PhOH_Tic__712CC607E630F981");

            entity.ToTable("PhOH_Tickets");

            entity.Property(e => e.TicketId).HasDefaultValueSql("(newid())");
            entity.Property(e => e.AsignadoAusuarioId)
                .HasMaxLength(128)
                .HasColumnName("AsignadoAUsuarioId");
            entity.Property(e => e.Categoria).HasMaxLength(50);
            entity.Property(e => e.CreadorUsuarioId).HasMaxLength(128);
            entity.Property(e => e.Departamento).HasMaxLength(50);
            entity.Property(e => e.Estado).HasMaxLength(50);
            entity.Property(e => e.FechaCreacion).HasColumnType("datetime");
            entity.Property(e => e.FechaEjecucion).HasColumnType("datetime");
            entity.Property(e => e.Impacto).HasMaxLength(50);
            entity.Property(e => e.Prioridad).HasMaxLength(50);
            entity.Property(e => e.Urgencia).HasMaxLength(50);
        });

        modelBuilder.Entity<PhSAccountType>(entity =>
        {
            entity.ToTable("PhS_AccountTypes");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.CreationDate)
                .HasDefaultValueSql("(getdate())")
                .HasColumnType("datetime")
                .HasColumnName("creation_date");
            entity.Property(e => e.CreditLimit)
                .HasColumnType("decimal(18, 2)")
                .HasColumnName("credit_limit");
            entity.Property(e => e.Description)
                .HasMaxLength(255)
                .HasColumnName("description");
            entity.Property(e => e.Name)
                .HasMaxLength(50)
                .HasColumnName("name");
        });

        modelBuilder.Entity<PhSAdjustmentReason>(entity =>
        {
            entity.HasKey(e => e.Code).HasName("PK__PhS_Adju__357D4CF809676D8C");

            entity.ToTable("PhS_AdjustmentReasons");

            entity.Property(e => e.Code)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("code");
            entity.Property(e => e.Active)
                .HasDefaultValue(true)
                .HasColumnName("active");
            entity.Property(e => e.Createdat)
                .HasDefaultValueSql("(getdate())")
                .HasColumnType("datetime")
                .HasColumnName("createdat");
            entity.Property(e => e.Description)
                .HasMaxLength(100)
                .HasColumnName("description");
        });

        modelBuilder.Entity<PhSBusinessUnit>(entity =>
        {
            entity.ToTable("PhS_BusinessUnits");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Code)
                .HasMaxLength(10)
                .HasColumnName("code");
            entity.Property(e => e.Description)
                .HasMaxLength(100)
                .HasColumnName("description");
            entity.Property(e => e.Manager)
                .HasMaxLength(50)
                .HasColumnName("manager");
        });

        modelBuilder.Entity<PhSCustomer>(entity =>
        {
            entity.ToTable("PhS_Customers");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.AccounttypesId).HasColumnName("accounttypes_id");
            entity.Property(e => e.Active).HasColumnName("active");
            entity.Property(e => e.BusinessName)
                .HasMaxLength(100)
                .HasColumnName("business_name");
            entity.Property(e => e.CreditLimit)
                .HasColumnType("decimal(18, 2)")
                .HasColumnName("credit_limit");
            entity.Property(e => e.ExternalCode)
                .HasMaxLength(10)
                .IsFixedLength()
                .HasColumnName("external_code");
            entity.Property(e => e.HasCreditAccount).HasColumnName("has_credit_account");
            entity.Property(e => e.Name)
                .HasMaxLength(100)
                .HasColumnName("name");
            entity.Property(e => e.TaxConditionId).HasColumnName("tax_condition_id");

            entity.HasOne(d => d.Accounttypes).WithMany(p => p.PhSCustomers)
                .HasForeignKey(d => d.AccounttypesId)
                .HasConstraintName("FK_PhS_Customers_PhS_AccountTypes");

            entity.HasOne(d => d.TaxCondition).WithMany(p => p.PhSCustomers)
                .HasForeignKey(d => d.TaxConditionId)
                .HasConstraintName("FK_PhS_Customers_PhOH_Tax_Conditions");
        });

        modelBuilder.Entity<PhSCustomerAddress>(entity =>
        {
            entity.ToTable("PhS_CustomerAddress");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.BusinessName)
                .HasMaxLength(100)
                .IsUnicode(false)
                .HasColumnName("business_name");
            entity.Property(e => e.City)
                .HasMaxLength(100)
                .IsUnicode(false)
                .HasColumnName("city");
            entity.Property(e => e.Country)
                .HasMaxLength(100)
                .IsUnicode(false)
                .HasColumnName("country");
            entity.Property(e => e.CustomersId).HasColumnName("customers_id");
            entity.Property(e => e.Email)
                .HasMaxLength(100)
                .IsUnicode(false)
                .HasColumnName("email");
            entity.Property(e => e.Latitude)
                .HasColumnType("decimal(9, 6)")
                .HasColumnName("latitude");
            entity.Property(e => e.Longitude)
                .HasColumnType("decimal(9, 6)")
                .HasColumnName("longitude");
            entity.Property(e => e.Notes)
                .HasMaxLength(255)
                .IsUnicode(false)
                .HasColumnName("notes");
            entity.Property(e => e.Phonenumber)
                .HasMaxLength(25)
                .IsUnicode(false)
                .HasColumnName("phonenumber");
            entity.Property(e => e.Postalcode)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasColumnName("postalcode");
            entity.Property(e => e.Stateprovince)
                .HasMaxLength(100)
                .IsUnicode(false)
                .HasColumnName("stateprovince");
            entity.Property(e => e.Streetaddress1)
                .HasMaxLength(255)
                .IsUnicode(false)
                .HasColumnName("streetaddress1");
            entity.Property(e => e.Streetaddress2)
                .HasMaxLength(255)
                .IsUnicode(false)
                .HasColumnName("streetaddress2");

            entity.HasOne(d => d.Customers).WithMany(p => p.PhSCustomerAddresses)
                .HasForeignKey(d => d.CustomersId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_PhS_CustomerAddress_PhS_Customers");
        });

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

            entity.ToTable("PhS_CustomerDocuments");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.CustomersId).HasColumnName("customers_id");
            entity.Property(e => e.DocumentNumber)
                .HasMaxLength(50)
                .HasColumnName("document_number");
            entity.Property(e => e.DocumenttypesId).HasColumnName("documenttypes_id");
            entity.Property(e => e.ExpiryDate).HasColumnName("expiry_date");
            entity.Property(e => e.IssueDate).HasColumnName("issue_date");

            entity.HasOne(d => d.Customers).WithMany(p => p.PhSCustomerDocuments)
                .HasForeignKey(d => d.CustomersId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK__PhS_Custo__custo__6754599E");

            entity.HasOne(d => d.Documenttypes).WithMany(p => p.PhSCustomerDocuments)
                .HasForeignKey(d => d.DocumenttypesId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_PhS_CustomerDocuments_PhS_DocumentTypes");
        });

        modelBuilder.Entity<PhSDocumentType>(entity =>
        {
            entity.ToTable("PhS_DocumentTypes");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Code)
                .HasMaxLength(4)
                .HasColumnName("code");
            entity.Property(e => e.Description)
                .HasMaxLength(255)
                .HasColumnName("description");
            entity.Property(e => e.Name)
                .HasMaxLength(100)
                .HasColumnName("name");
        });

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

            entity.ToTable("PhS_FormSeries", tb => tb.HasComment("FormSeries: talonarios/series por tipo de formulario, letra y punto de venta."));

            entity.HasIndex(e => e.FormtypeId, "IX_PhS_FormSeries_FormType");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Createdat)
                .HasDefaultValueSql("(getdate())")
                .HasColumnType("datetime")
                .HasColumnName("createdat");
            entity.Property(e => e.FormtypeId)
                .HasComment("FK a tipo de formulario (PhS_FormTypes).")
                .HasColumnName("formtype_id");
            entity.Property(e => e.Isactive)
                .HasDefaultValue(true)
                .HasComment("Indica si está habilitada.")
                .HasColumnName("isactive");
            entity.Property(e => e.Isdefault)
                .HasComment("Marca esta serie como predeterminada.")
                .HasColumnName("isdefault");
            entity.Property(e => e.Letter)
                .HasMaxLength(1)
                .IsUnicode(false)
                .IsFixedLength()
                .HasComment("Letra de serie (A,B,C...).")
                .HasColumnName("letter");
            entity.Property(e => e.Modifiedat)
                .HasColumnType("datetime")
                .HasColumnName("modifiedat");
            entity.Property(e => e.NumberingSource)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasDefaultValue("INTERNAL")
                .HasColumnName("numbering_source");
            entity.Property(e => e.Pointofsale)
                .HasComment("Punto de venta asignado.")
                .HasColumnName("pointofsale");

            entity.HasOne(d => d.Formtype).WithMany(p => p.PhSFormSeries)
                .HasForeignKey(d => d.FormtypeId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_PhS_FormSeries_FormTypes");
        });

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

            entity.ToTable("PhS_FormSeriesNextNumber", tb => tb.HasComment("Mantiene el siguiente número correlativo para cada FormSeries."));

            entity.HasIndex(e => e.FormseriesId, "IX_PhS_NextNumber_FormSeriesId").IsUnique();

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.FormseriesId)
                .HasComment("FK a PhS_FormSeries.")
                .HasColumnName("formseries_id");
            entity.Property(e => e.Nextnumber)
                .HasComment("Próximo número correlativo.")
                .HasColumnName("nextnumber");

            entity.HasOne(d => d.Formseries).WithOne(p => p.PhSFormSeriesNextNumber)
                .HasForeignKey<PhSFormSeriesNextNumber>(d => d.FormseriesId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_PhS_NextNumber_FormSeries");
        });

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

            entity.ToTable("PhS_FormTypes", tb => tb.HasComment("Tipos genéricos de formularios del sistema (presupuesto, factura, recibo, etc.)"));

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Code)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasColumnName("code");
            entity.Property(e => e.Name)
                .HasMaxLength(100)
                .HasColumnName("name");
        });

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

            entity.ToTable("PhS_Institutions");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.City)
                .HasMaxLength(100)
                .HasColumnName("city");
            entity.Property(e => e.Createdat)
                .HasDefaultValueSql("(getdate())")
                .HasColumnType("datetime")
                .HasColumnName("createdat");
            entity.Property(e => e.Email)
                .HasMaxLength(150)
                .HasColumnName("email");
            entity.Property(e => e.Isactive)
                .HasDefaultValue(true)
                .HasColumnName("isactive");
            entity.Property(e => e.Name)
                .HasMaxLength(200)
                .HasColumnName("name");
            entity.Property(e => e.Operatingroominfo)
                .HasMaxLength(200)
                .HasColumnName("operatingroominfo");
            entity.Property(e => e.Phone)
                .HasMaxLength(50)
                .HasColumnName("phone");
            entity.Property(e => e.Province)
                .HasMaxLength(100)
                .HasColumnName("province");
            entity.Property(e => e.Streetaddress)
                .HasMaxLength(250)
                .HasColumnName("streetaddress");
            entity.Property(e => e.Type)
                .HasMaxLength(15)
                .HasColumnName("type");
        });

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

            entity.ToTable("PhS_Patients");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Address)
                .HasMaxLength(250)
                .HasColumnName("address");
            entity.Property(e => e.AffiliateNumber)
                .HasMaxLength(100)
                .HasColumnName("affiliate_number");
            entity.Property(e => e.Birthdate).HasColumnName("birthdate");
            entity.Property(e => e.Createdat)
                .HasDefaultValueSql("(getdate())")
                .HasColumnType("datetime")
                .HasColumnName("createdat");
            entity.Property(e => e.CustomerId).HasColumnName("customer_id");
            entity.Property(e => e.DocumentNumber)
                .HasMaxLength(50)
                .HasColumnName("document_number");
            entity.Property(e => e.DocumenttypesId).HasColumnName("documenttypes_id");
            entity.Property(e => e.Email)
                .HasMaxLength(150)
                .HasColumnName("email");
            entity.Property(e => e.Firstname)
                .HasMaxLength(100)
                .HasColumnName("firstname");
            entity.Property(e => e.Gender)
                .HasMaxLength(10)
                .HasColumnName("gender");
            entity.Property(e => e.Lastname)
                .HasMaxLength(100)
                .HasColumnName("lastname");
            entity.Property(e => e.Modifiedat)
                .HasColumnType("datetime")
                .HasColumnName("modifiedat");
            entity.Property(e => e.Notes).HasColumnName("notes");
            entity.Property(e => e.Phone)
                .HasMaxLength(50)
                .HasColumnName("phone");

            entity.HasOne(d => d.Customer).WithMany(p => p.PhSPatients)
                .HasForeignKey(d => d.CustomerId)
                .HasConstraintName("FK_Patients_Customers");

            entity.HasOne(d => d.Documenttypes).WithMany(p => p.PhSPatients)
                .HasForeignKey(d => d.DocumenttypesId)
                .HasConstraintName("FK_Patients_DocumentTypes");
        });

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

            entity.ToTable("PhS_PeopleGroups");

            entity.Property(e => e.Id)
                .HasComment("Identificador único del grupo de personas")
                .HasColumnName("id");
            entity.Property(e => e.Active)
                .HasDefaultValue(true)
                .HasComment("Estado activo o inactivo del grupo")
                .HasColumnName("active");
            entity.Property(e => e.BusinessunitsId)
                .HasComment("Unidad de negocio relacionada (opcional)")
                .HasColumnName("businessunits_id");
            entity.Property(e => e.CreatedAt)
                .HasDefaultValueSql("(getdate())")
                .HasComment("Fecha de creación del grupo")
                .HasColumnType("datetime")
                .HasColumnName("created_at");
            entity.Property(e => e.Description)
                .HasMaxLength(255)
                .HasComment("Descripción adicional del grupo")
                .HasColumnName("description");
            entity.Property(e => e.ModifiedAt)
                .HasComment("Fecha de última modificación")
                .HasColumnType("datetime")
                .HasColumnName("modified_at");
            entity.Property(e => e.Name)
                .HasMaxLength(100)
                .HasComment("Nombre del grupo de vendedores")
                .HasColumnName("name");
        });

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

            entity.ToTable("PhS_People");

            entity.Property(e => e.Id)
                .HasComment("Identificador único de la persona (vendedor/agente)")
                .HasColumnName("id");
            entity.Property(e => e.Active)
                .HasDefaultValue(true)
                .HasComment("Activo/Inactivo")
                .HasColumnName("active");
            entity.Property(e => e.BusinessunitsId)
                .HasComment("Unidad de negocio asignada")
                .HasColumnName("businessunits_id");
            entity.Property(e => e.CreatedAt)
                .HasDefaultValueSql("(getdate())")
                .HasComment("Fecha de creación")
                .HasColumnType("datetime")
                .HasColumnName("created_at");
            entity.Property(e => e.DefaultCommissionPercent)
                .HasComment("Porcentaje de comisión por defecto")
                .HasColumnType("decimal(5, 2)")
                .HasColumnName("default_commission_percent");
            entity.Property(e => e.Email)
                .HasMaxLength(100)
                .HasComment("Correo electrónico de la persona")
                .HasColumnName("email");
            entity.Property(e => e.ModifiedAt)
                .HasComment("Fecha de última modificación")
                .HasColumnType("datetime")
                .HasColumnName("modified_at");
            entity.Property(e => e.Name)
                .HasMaxLength(100)
                .HasComment("Nombre de la persona")
                .HasColumnName("name");
            entity.Property(e => e.PeoplegroupsId)
                .HasComment("Grupo comercial opcional")
                .HasColumnName("peoplegroups_id");
            entity.Property(e => e.Phone)
                .HasMaxLength(50)
                .HasComment("Teléfono de contacto de la persona")
                .HasColumnName("phone");

            entity.HasOne(d => d.Businessunits).WithMany(p => p.PhSPeople)
                .HasForeignKey(d => d.BusinessunitsId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_people_businessunits");

            entity.HasOne(d => d.Peoplegroups).WithMany(p => p.PhSPeople)
                .HasForeignKey(d => d.PeoplegroupsId)
                .HasConstraintName("FK_people_peoplegroups");
        });

        modelBuilder.Entity<PhSProduct>(entity =>
        {
            entity.ToTable("PhS_Products");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Baseprice)
                .HasColumnType("decimal(18, 2)")
                .HasColumnName("baseprice");
            entity.Property(e => e.BusinessunitsId).HasColumnName("businessunits_id");
            entity.Property(e => e.Categoryid).HasColumnName("categoryid");
            entity.Property(e => e.Currency)
                .HasMaxLength(3)
                .IsUnicode(false)
                .HasDefaultValue("ARS")
                .HasColumnName("currency");
            entity.Property(e => e.Description).HasColumnName("description");
            entity.Property(e => e.Isactive)
                .HasDefaultValue(true)
                .HasColumnName("isactive");
            entity.Property(e => e.Name)
                .HasMaxLength(100)
                .IsFixedLength()
                .HasColumnName("name");
            entity.Property(e => e.Origin)
                .HasMaxLength(12)
                .IsUnicode(false)
                .HasColumnName("origin");

            entity.HasOne(d => d.Businessunits).WithMany(p => p.PhSProducts)
                .HasForeignKey(d => d.BusinessunitsId)
                .HasConstraintName("FK_PhS_Products_PhS_BusinessUnits");

            entity.HasOne(d => d.Category).WithMany(p => p.PhSProducts)
                .HasForeignKey(d => d.Categoryid)
                .HasConstraintName("FK_PhS_Products_Categories");
        });

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

            entity.ToTable("PhS_ProductCategories");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Description)
                .HasMaxLength(250)
                .HasColumnName("description");
            entity.Property(e => e.Isactive)
                .HasDefaultValue(true)
                .HasColumnName("isactive");
            entity.Property(e => e.Name)
                .HasMaxLength(100)
                .HasColumnName("name");
        });

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

            entity.ToTable("PhS_Professionals");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Active)
                .HasDefaultValue(true)
                .HasColumnName("active");
            entity.Property(e => e.Address)
                .HasMaxLength(250)
                .HasColumnName("address");
            entity.Property(e => e.City)
                .HasMaxLength(100)
                .HasColumnName("city");
            entity.Property(e => e.Createdat)
                .HasDefaultValueSql("(getdate())")
                .HasColumnType("datetime")
                .HasColumnName("createdat");
            entity.Property(e => e.DocumentNumber)
                .HasMaxLength(50)
                .HasColumnName("document_number");
            entity.Property(e => e.DocumenttypeName)
                .HasMaxLength(100)
                .HasColumnName("documenttype_name");
            entity.Property(e => e.Email)
                .HasMaxLength(150)
                .HasColumnName("email");
            entity.Property(e => e.Fullname)
                .HasMaxLength(200)
                .HasColumnName("fullname");
            entity.Property(e => e.License)
                .HasMaxLength(50)
                .HasColumnName("license");
            entity.Property(e => e.Phone1)
                .HasMaxLength(50)
                .HasColumnName("phone1");
            entity.Property(e => e.Phone2)
                .HasMaxLength(50)
                .HasColumnName("phone2");
            entity.Property(e => e.Postalcode)
                .HasMaxLength(20)
                .HasColumnName("postalcode");
            entity.Property(e => e.Province)
                .HasMaxLength(100)
                .HasColumnName("province");
            entity.Property(e => e.SpecialtyId).HasColumnName("specialty_id");
            entity.Property(e => e.Type)
                .HasMaxLength(25)
                .HasColumnName("type");

            entity.HasOne(d => d.Specialty).WithMany(p => p.PhSProfessionals)
                .HasForeignKey(d => d.SpecialtyId)
                .HasConstraintName("FK_Professionals_Specialty");
        });

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

            entity.ToTable("PhS_ProfessionalSpecialties");

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Active)
                .HasDefaultValue(true)
                .HasColumnName("active");
            entity.Property(e => e.Name)
                .HasMaxLength(100)
                .HasColumnName("name");
        });

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

            entity.ToTable("PhS_QuoteAdjustments", tb => tb.HasComment("Tabla de ajustes aplicados a presupuestos comerciales"));

            entity.Property(e => e.Id)
                .HasComment("ID interno del ajuste aplicado al presupuesto")
                .HasColumnName("id");
            entity.Property(e => e.Amount)
                .HasComment("Importe del ajuste realizado (positivo o nulo)")
                .HasColumnType("decimal(18, 2)")
                .HasColumnName("amount");
            entity.Property(e => e.Createdat)
                .HasDefaultValueSql("(getdate())")
                .HasComment("Fecha de registro del ajuste")
                .HasColumnType("datetime")
                .HasColumnName("createdat");
            entity.Property(e => e.Description)
                .HasMaxLength(255)
                .HasComment("Descripción adicional del ajuste")
                .HasColumnName("description");
            entity.Property(e => e.QuoteheaderId)
                .HasComment("FK al presupuesto (PhS_QuoteHeaders)")
                .HasColumnName("quoteheader_id");
            entity.Property(e => e.ReasonCode)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("Código del motivo de ajuste (FK a PhS_AdjustmentReasons)")
                .HasColumnName("reason_code");

            entity.HasOne(d => d.Quoteheader).WithMany(p => p.PhSQuoteAdjustments)
                .HasForeignKey(d => d.QuoteheaderId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_QuoteAdjustments_Header");

            entity.HasOne(d => d.ReasonCodeNavigation).WithMany(p => p.PhSQuoteAdjustments)
                .HasForeignKey(d => d.ReasonCode)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_QuoteAdjustments_Reason");
        });

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

            entity.ToTable("PhS_QuoteDetails", tb => tb.HasComment("Tabla de detalles de presupuestos"));

            entity.Property(e => e.Id)
                .HasComment("ID interno")
                .HasColumnName("id");
            entity.Property(e => e.Approved)
                .HasComment("¿Aprobado? (0=No, 1=Si)")
                .HasColumnName("approved");
            entity.Property(e => e.Approvedamount)
                .HasComment("Importe aprobado final")
                .HasColumnType("decimal(18, 2)")
                .HasColumnName("approvedamount");
            entity.Property(e => e.Createdat)
                .HasDefaultValueSql("(getdate())")
                .HasComment("Fecha de creación del registro")
                .HasColumnType("datetime")
                .HasColumnName("createdat");
            entity.Property(e => e.Modifiedat)
                .HasComment("Fecha de última modificación")
                .HasColumnType("datetime")
                .HasColumnName("modifiedat");
            entity.Property(e => e.ProductDescription)
                .HasComment("Descripción modificable del producto (puede diferir del original)")
                .HasColumnName("product_description");
            entity.Property(e => e.ProductId)
                .HasComment("ID del producto original")
                .HasColumnName("product_id");
            entity.Property(e => e.Quantity)
                .HasDefaultValue(1)
                .HasComment("Cantidad")
                .HasColumnName("quantity");
            entity.Property(e => e.QuoteheaderId)
                .HasComment("FK a encabezado de presupuesto")
                .HasColumnName("quoteheader_id");
            entity.Property(e => e.Unitprice)
                .HasComment("Precio unitario original")
                .HasColumnType("decimal(18, 2)")
                .HasColumnName("unitprice");

            entity.HasOne(d => d.Product).WithMany(p => p.PhSQuoteDetails)
                .HasForeignKey(d => d.ProductId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_PhS_QuoteDetails_PhS_Products");

            entity.HasOne(d => d.Quoteheader).WithMany(p => p.PhSQuoteDetails)
                .HasForeignKey(d => d.QuoteheaderId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_QuoteDetails_Header");
        });

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

            entity.ToTable("PhS_QuoteHeaders", tb => tb.HasComment("Tabla de cabeceras de presupuestos"));

            entity.Property(e => e.Id)
                .HasComment("ID interno")
                .HasColumnName("id");
            entity.Property(e => e.Approvaldate)
                .HasComment("Fecha de aprobación")
                .HasColumnName("approvaldate");
            entity.Property(e => e.Approvedamount)
                .HasComment("Importe aprobado")
                .HasColumnType("decimal(18, 2)")
                .HasColumnName("approvedamount");
            entity.Property(e => e.BusinessunitId)
                .HasComment("Unidad de negocio")
                .HasColumnName("businessunit_id");
            entity.Property(e => e.Createdat)
                .HasDefaultValueSql("(getdate())")
                .HasComment("Fecha de creación")
                .HasColumnType("datetime")
                .HasColumnName("createdat");
            entity.Property(e => e.Currency)
                .HasMaxLength(3)
                .IsUnicode(false)
                .HasDefaultValue("ARS")
                .HasComment("Código de moneda pactada (ISO 4217). Ej: ARS, USD")
                .HasColumnName("currency");
            entity.Property(e => e.CustomerId)
                .HasComment("Cliente asociado")
                .HasColumnName("customer_id");
            entity.Property(e => e.DispatchInstruction)
                .HasMaxLength(255)
                .HasComment("Instrucción dirigida al área de logística para detallar qué debe prepararse o despacharse (ej: “CMF 1.5 + INSTRUMENTAL”)")
                .HasColumnName("dispatch_instruction");
            entity.Property(e => e.Estimateddate)
                .HasComment("Fecha tentativa (de cirugía por ej.)")
                .HasColumnType("datetime")
                .HasColumnName("estimateddate");
            entity.Property(e => e.Exchangerate)
                .HasComment("Tipo de cambio pactado para conversión a pesos argentinos")
                .HasColumnType("decimal(18, 6)")
                .HasColumnName("exchangerate");
            entity.Property(e => e.Issuedate)
                .HasDefaultValueSql("(getdate())")
                .HasComment("Fecha de emisión")
                .HasColumnType("datetime")
                .HasColumnName("issuedate");
            entity.Property(e => e.Modifiedat)
                .HasComment("Fecha de modificación")
                .HasColumnType("datetime")
                .HasColumnName("modifiedat");
            entity.Property(e => e.Netamount)
                .HasComment("Importe neto antes de aplicar impuestos, expresado en la moneda pactada del presupuesto")
                .HasColumnType("decimal(18, 2)")
                .HasColumnName("netamount");
            entity.Property(e => e.Observations)
                .HasComment("Observaciones internas")
                .HasColumnName("observations");
            entity.Property(e => e.OutOfTown)
                .HasComment("Indica si la cirugía se realizará fuera de la ciudad/localidad habitual (“out of town”)")
                .HasColumnName("out_of_town");
            entity.Property(e => e.PeopleId)
                .HasDefaultValue(1)
                .HasComment("Identificador único del vendedor")
                .HasColumnName("people_id");
            entity.Property(e => e.Printcount)
                .HasComment("Cantidad de impresiones")
                .HasColumnName("printcount");
            entity.Property(e => e.Quotenumber)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasComment("Número visible del presupuesto")
                .HasColumnName("quotenumber");
            entity.Property(e => e.Status)
                .HasMaxLength(15)
                .IsUnicode(false)
                .HasDefaultValue("Emitido")
                .HasComment("Estado: E (Emitido), A (Aprobado), AC (Aprobado para cirugia), etc.")
                .HasColumnName("status");
            entity.Property(e => e.TicketId)
                .HasComment("Relación con Tickets")
                .HasColumnName("ticket_id");
            entity.Property(e => e.Total)
                .HasComment("Importe total del presupuesto en moneda local, calculado incluyendo impuestos y convertido según tipo de cambio pactado")
                .HasColumnType("decimal(18, 2)")
                .HasColumnName("total");
            entity.Property(e => e.TotalForeign)
                .HasComment("Importe total del presupuesto expresado en la moneda pactada (extranjera), incluyendo impuestos y ajustes comerciales")
                .HasColumnType("decimal(18, 2)")
                .HasColumnName("total_foreign");
        });

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

            entity.ToTable("PhS_QuoteRoles", tb => tb.HasComment("Tabla de roles asociados a presupuestos"));

            entity.HasIndex(e => new { e.Entitytype, e.EntityId }, "IX_QuoteRoles_Entity");

            entity.HasIndex(e => e.QuoteheaderId, "IX_QuoteRoles_HeaderId");

            entity.HasIndex(e => e.Role, "IX_QuoteRoles_Role");

            entity.Property(e => e.Id)
                .HasComment("ID interno")
                .HasColumnName("id");
            entity.Property(e => e.EntityId)
                .HasComment("ID de la entidad asociada")
                .HasColumnName("entity_id");
            entity.Property(e => e.Entitytype)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("Tipo de entidad asociada (Ej: PhS_Professionals, PhS_Institutions, PhS_Patients)")
                .HasColumnName("entitytype");
            entity.Property(e => e.QuoteheaderId)
                .HasComment("FK a encabezado de presupuesto (PhS_QuoteHeaders)")
                .HasColumnName("quoteheader_id");
            entity.Property(e => e.Role)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("Rol que cumple la entidad en el presupuesto (Ej: Medico, Hospital, Paciente)")
                .HasColumnName("role");

            entity.HasOne(d => d.Quoteheader).WithMany(p => p.PhSQuoteRoles)
                .HasForeignKey(d => d.QuoteheaderId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_QuoteRoles_Header");
        });

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

            entity.ToTable("PhS_QuoteTaxes");

            entity.Property(e => e.Id)
                .HasComment("Clave primaria autoincremental")
                .HasColumnName("id");
            entity.Property(e => e.CreatedAt)
                .HasDefaultValueSql("(getdate())")
                .HasComment("Fecha de creación del registro")
                .HasColumnType("datetime")
                .HasColumnName("created_at");
            entity.Property(e => e.IsIncludedInPrice)
                .HasComment("Indica si el impuesto está incluido en el precio final (1 = sí)")
                .HasColumnName("is_included_in_price");
            entity.Property(e => e.ModifiedAt)
                .HasComment("Fecha de modificación del registro")
                .HasColumnType("datetime")
                .HasColumnName("modified_at");
            entity.Property(e => e.QuoteheaderId)
                .HasComment("Referencia al presupuesto (PhS_QuoteHeaders)")
                .HasColumnName("quoteheader_id");
            entity.Property(e => e.TaxableAmount)
                .HasComment("Base imponible del impuesto (importe gravado)")
                .HasColumnType("decimal(18, 2)")
                .HasColumnName("taxable_amount");
            entity.Property(e => e.Taxamount)
                .HasComment("Importe final del impuesto calculado")
                .HasColumnType("decimal(18, 2)")
                .HasColumnName("taxamount");
            entity.Property(e => e.Taxcode)
                .HasMaxLength(50)
                .HasComment("Código o identificador oficial del impuesto (ej. AFIP)")
                .HasColumnName("taxcode");
            entity.Property(e => e.Taxname)
                .HasMaxLength(100)
                .HasComment("Nombre descriptivo del impuesto")
                .HasColumnName("taxname");
            entity.Property(e => e.Taxrate)
                .HasComment("Alícuota aplicada (porcentaje)")
                .HasColumnType("decimal(5, 2)")
                .HasColumnName("taxrate");

            entity.HasOne(d => d.Quoteheader).WithMany(p => p.PhSQuoteTaxes)
                .HasForeignKey(d => d.QuoteheaderId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_PhS_QuoteTaxes_QuoteHeaders");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
