using Prism.Events;

namespace ProximaAnalizer.ViewModels.DBInfoAlarmRegions;

partial class AlarmGasPanelViewModel : ObservableObject
{
    public AlarmGasPanelViewModel(IEventAggregator eventAggregator)
    {
        this._eventAggregator = eventAggregator;
        eventAggregator.GetEvent<UpdateAlarmData>().Subscribe(UpdateData);

    }

    private IEventAggregator _eventAggregator;
    private void UpdateData()
    {
        this.DataChanged(_eventAggregator.GetEvent<UpdateAlarmData>().PmData, _eventAggregator.GetEvent<UpdateAlarmData>().SystemData);
    }


    private void DataChanged(List<dynamic>? pmData, List<dynamic>? systemData)
    {
        App.Current.Dispatcher?.Invoke(() =>
        {
            this.MFCs.UpdateData(pmData);
            this.Valves.UpdateData(pmData);
            this.Sensor.UpdateData(pmData);

            //this.Data = null;
            //this.Data = this.MFCs.Data;
            //this.Data = this.Valves.Data;
            //this.Data = this.Sensor.Data;
            this.Data = new KeyValuePair<string, object>("MFC", this.MFCs.Data);
            this.Data = new KeyValuePair<string, object>("Valve", this.Valves.Data);
            this.Data = new KeyValuePair<string, object>("Sensor", this.Sensor.Data);
        });
    }

    [ObservableProperty]
    private object? _Data;

    [ObservableProperty]
    private DisplayHistroyHelper2 _MFCs = new(1, 2, "MF");

    [ObservableProperty]
    private DisplayHistroyHelper2 _Valves = new(2, 3, "IoValve");


    [ObservableProperty]
    private DisplayHistroyHelper2 _Sensor = new(1, 2, "Sensor");
}
