using adas_core.Domain.Enums;
using MongoDB.Bson;

namespace adas_core.Domain.Models.Pumps
{
    /// <summary>
    /// Datos unificados de entrada (del HL7): transporta la información
    /// de observaciones (PCD-01/10), alarmas (PCD-04) y eventos. El servicio
    /// decidirá cómo dividir y persistir en las colecciones destino.
    /// </summary>
    public class PumpObservation
    {
        public ObjectId Id { get; set; } 
        public ObjectId? PatientId { get; set; } 
        public DateTime Time { get; set; }
        
        // Identificadores / dispositivo
        public string? DeviceId { get; set; }
        public string? RackId { get; set; }
        public string? DeviceTypeMdc { get; set; }

        // Infusión / tiempo
        public string? InfusionId { get; set; }

        /// <summary>Tipo semántico de este DTO: Observation (PCD-01/10) o Alarm (PCD-04).</summary>
        public PumpEnum.PumpMessageType MessageType { get; set; }

        #region PROPIEDADES DE LA CLASE ORIGINAL
        //necesarios para que funcione Alaris
        //TODO verificar
        public int? TotalAux { get; set; }
        public CommonPumpTypes.PumpValue? Pressure { get; set; }
        public CommonPumpTypes.PumpValue? DiluentVolume { get; set; }
        public CommonPumpTypes.PumpValue? PatientHeight { get; set; }
        public int GatewayNumber { get; set; }
        public int? Expires { get; set; }
        public Dictionary<string, object>? UiConfiguration { get; set; }
        public CommonPumpTypes.PumpValue? BasalRate { get; set; }
        public string? Code { get; set; }
        public string? Name { get; set; }

        public int? Number { get; set; }
        public int? Total { get; set; }
        public bool? IsAux  { get; set; }
        public PumpEnum.AlarmMode? AlarmMode { get; set; }
        
        #endregion
        
        
        // ============================
        // OBSERVACIONES (PCD-01 / 10)
        // ============================
        public bool? IsInfusing { get; set; }
        public PumpEnum.InfusingStatus? InfusingStatus { get; set; }
        public PumpEnum.Status? Status { get; set; }
        public PumpEnum.Mode? PumpMode { get; set; }

        public string? ActiveSourceInfo { get; set; }      // Primary/Clinician/Loading/Priming
        public string? InfusionModeDetail { get; set; }    // Texto del modo
        public string? NotDeliveringReason { get; set; }
        public string? Source { get; set; }                // primary-source, clinician-source...

        public CommonPumpTypes.PumpValue? FlowFluid { get; set; }        // actual
        public CommonPumpTypes.PumpValue? Rate { get; set; }             // programada
        public CommonPumpTypes.PumpValue? VolumeInfused { get; set; }    // segmento
        public CommonPumpTypes.PumpValue? FluidDelivTotal { get; set; }  // total
        public CommonPumpTypes.PumpValue? FluidDelivTotalSet { get; set; } // acumulado
        public CommonPumpTypes.PumpValue? VolumeRemaining { get; set; }
        public CommonPumpTypes.PumpValue? Vtbi { get; set; }
        public CommonPumpTypes.PumpValue? TimeRemaining { get; set; }    // seg
        public CommonPumpTypes.PumpValue? TimeProgrammed { get; set; }   // seg

        // Medicación / dosis
        public string? DrugName { get; set; }
        public string? DrugId { get; set; }
        public CommonPumpTypes.PumpValue? Concentration { get; set; }
        public CommonPumpTypes.PumpValue? DoseRate { get; set; }
        public CommonPumpTypes.PumpValue? DrugAmount { get; set; }         // TBI
        public CommonPumpTypes.PumpValue? DrugDoseDelivered { get; set; }  // total

        public CommonPumpTypes.PumpValue? PatientWeight { get; set; }
        public CommonPumpTypes.SyringeDetails? Syringe { get; set; }

        // Ubicación física / red
        public string? DeviceIp { get; set; }
        public string? PillarAssembly { get; set; }    // "1,1,4,pillar-orientation-vertical,slot-rackdirection-down"
        public string? PillarRackSlot { get; set; }    // "1,2,3,NA"

        // ============================
        // ALARMAS (PCD-04)
        // ============================
        public PumpEnum.AlarmType? AlarmType { get; set; }
        public string? AlarmDescription { get; set; }
        public string? AlarmState { get; set; }                // active/inactive/latched
        public string? AlarmInactivationState { get; set; }    // enabled / alert-acknowledged~audio-paused
        public string? AlarmPriority { get; set; }             // PL/PM/PH
        public string? AlarmTypeMdc { get; set; }              // e.g., "ST"
        public PumpEnum.EventPhase? EventPhase { get; set; }   // start/continue/end
        public string? AlertSourceMdc { get; set; }

        // ============================
        // EVENTOS (PCD-10)
        // ============================
        public PumpEnum.Event? Event { get; set; }
    }

    
}
