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

namespace adas_core.Domain.Models.Pumps
{
    /// <summary>
    /// Snapshot vivo de la bomba, indexado por DeviceId.
    /// Se sobrescribe con cada mensaje del HL7.
    /// Contiene siempre el último valor conocido de la bomba.
    /// </summary>
    public class PumpState
    {
        public ObjectId Id { get; set; }

        // Identificación bomba
        public string? DeviceId { get; set; }
        public string? RackId { get; set; }
        public string? DeviceTypeMdc { get; set; }

        // Ubicación física
        public string? DeviceIp { get; set; }
        public string? PillarAssembly { get; set; }
        public string? PillarRackSlot { get; set; }

        // Paciente asociado (si existe)
        public ObjectId? PatientId { get; set; }

        // Infusión activa
        public string? InfusionId { get; set; }
        public DateTime LastUpdated { get; set; }

        // Estado general
        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? InfusionModeDetail { get; set; }
        public string? ActiveSourceInfo { get; set; }
        public string? NotDeliveringReason { get; set; }
        public string? Source { get; set; }

        // Métricas
        public CommonPumpTypes.PumpValue? FlowFluid { get; set; }
        public CommonPumpTypes.PumpValue? Rate { get; set; }
        public CommonPumpTypes.PumpValue? VolumeInfused { get; set; }
        public CommonPumpTypes.PumpValue? FluidDelivTotal { get; set; }
        public CommonPumpTypes.PumpValue? FluidDelivTotalSet { get; set; }
        public CommonPumpTypes.PumpValue? VolumeRemaining { get; set; }
        public CommonPumpTypes.PumpValue? Vtbi { get; set; }
        public CommonPumpTypes.PumpValue? TimeRemaining { get; set; }
        public CommonPumpTypes.PumpValue? TimeProgrammed { get; set; }

        // Medicación
        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; }
        public CommonPumpTypes.PumpValue? DrugDoseDelivered { get; set; }

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

        // Última alarma recibida
        public PumpEnum.AlarmType? AlarmType { get; set; }
        public string? AlarmDescription { get; set; }
        public string? AlarmState { get; set; }
        public string? AlarmInactivationState { get; set; }
        public string? AlarmPriority { get; set; }
        public string? AlarmCodeMdc { get; set; }

        // Evento último
        public PumpEnum.Event? Event { get; set; }
        public PumpEnum.EventPhase? EventPhase { get; set; }

        // Comunicación / Relay
        public string? CommStatus { get; set; }
        public string? RelayState { get; set; }
        public string? RelayGuid { get; set; }
    }
}