using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BPASmartClient.Helper;
using BPASmartClient.Model;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;

namespace BPASmartClient.ViewModel
{
    public class SystemSetViewModel : ObservableObject
    {
        public SystemSetViewModel()
        {
            if (SaveInfoCommand == null)
            {
                SaveInfoCommand = new Action(() =>
                {
                    List<ushort> values = new List<ushort>();
                    values.Clear();

                    List<bool> bools = new List<bool>();
                    bools.Clear();

                    for (int i = 0; i < Json<KeepDataBase>.Data.parSets.Count; i++)
                    {
                        values.Clear();
                        values.Add(Json<KeepDataBase>.Data.parSets[i].Minute);
                        values.Add(Json<KeepDataBase>.Data.parSets[i].Second);
                        bools.Add(Json<KeepDataBase>.Data.parSets[i].IsShield);
                        //ModbusTcpHelper.GetInstance.Write((ushort)ModbusTcpHelper.GetInstance.GetWordAddress($"VW{116 + (i * 6)}"), WriteType.HoldingRegisters, values.ToArray());
                    }
                    //ModbusTcpHelper.GetInstance.Write((ushort)ModbusTcpHelper.GetInstance.GetBoolAddress("M260.0"), WriteType.Coils, bools.ToArray());

                });
            }
        }

        public ObservableCollection<ParSet> parSets { get; set; } = Json<KeepDataBase>.Data.parSets;
        public Action SaveInfoCommand { get; set; }

    }
}
