using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using GeneralData;
using UICommon.DataType;

namespace GlobalData;

public partial class DeviceData_VM : ObservableObject
{
    public Guid DeviceId { get; set; }

    [ObservableProperty]
    private DeviceModel _DeviceModel;

    [ObservableProperty]
    private string? _DeviceStatus;

    [ObservableProperty]
    public ObservableDictionary<string, object> _OtherInfo = [];


    [ObservableProperty]
    private RecipeInfo_VM? _RecipeInfo;

    [ObservableProperty]
    private ObservableCollection<Alarm_VM>? _Alarms;

    partial void OnAlarmsChanged(ObservableCollection<Alarm_VM>? value)
    {
        if (this.Alarms is null)
            return;
        this.Alarms.CollectionChanged -= Alarms_CollectionChanged;
        this.Alarms.CollectionChanged += Alarms_CollectionChanged;

    }

    private void Alarms_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        if (sender is not ObservableCollection<Alarm_VM> value)
        {
            this.AlarmCount = 0;
            return;
        }

        this.AlarmCount = value.Count;
    }

    [ObservableProperty]
    private int _AlarmCount;
}