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;
}

public enum PMCMode
{
    Undefined,
    Running
}

public enum DeviceStatus
{
    Init = 0,
    Initializing,
    Idle,
    Transfer,
    AutoRunning,
    AutoIdel = 5,
    ReturnAllWafer,
    Error,
    Loading,
    Unloading,
    ChargeProcessDischarging = 10,
    LoadProcessStockering,
    LoadProcessUnloading,
    ReutrnWafer
}

public enum TubeStatus
{
    NotInstall,
    NotConnected,
    Init,
    Idle,
    Homing,
    OpenSlitValve,
    CloseSlitValve,
    Error,
    PrepareTransfer,
    PostTransfer,
    PreProcess,
    PostProcess,
    Process,
    LeakCheck,
    MFCCali,
    Pauded,
    InTransfer
}

public enum RecipeType
{
    Undefined,
    PorcessRecipe,
    SubRecipe,
    AlarmRecipe,
    AbortRecipe,
    ResetRecipe,
    IdleRecipe,
    LayoutRecipe,
    JobRecipe
}

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

    [ObservableProperty]
    private string? _AlarmCode;
    [ObservableProperty]
    private DateTime _AlarmTime;
    [ObservableProperty]
    private string? _AlarmName;
}

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

    //[ObservableProperty]
    //private RecipeType _RecipeType;

    //[ObservableProperty]
    //private string? _PJobID;

    //[ObservableProperty]
    //private string? _CJboID;

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

    [ObservableProperty]
    private string? _CurrentStepName;
    [ObservableProperty]
    private string? _NextStepName;

    [ObservableProperty]
    private int? _CurrentStepRemainTime;
    [ObservableProperty]
    private int? _CurrentStepTotalTime;

    [ObservableProperty]
    private int? _TotalTime;
    [ObservableProperty]
    private int? _TotalRemainTime;
}