using SWRIS.Dtos;
using SWRIS.Enums;
using SWRIS.Extensions;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO.Ports;
using System.Linq;

namespace SWRIS.Models
{
    public class CalibrationDataModel : INotifyPropertyChanged
    {
        private int moduleType;
        private TcpDataModel tcp;
        private SerialDataModel serial;
        private ObservableCollection<LimitDataModel> limits;
        public int ModuleType
        {
            get => moduleType;
            set
            {
                moduleType = value;
                OnPropertyChanged(nameof(ModuleType));
            }
        }
        public TcpDataModel Tcp
        {
            get => tcp;
            set
            {
                tcp = value;
                OnPropertyChanged(nameof(Tcp));
            }
        }
        public SerialDataModel Serial
        {
            get => serial;
            set
            {
                serial = value;
                OnPropertyChanged(nameof(Serial));
            }
        }
        public ObservableCollection<LimitDataModel> Limits
        {
            get => limits;
            set
            {
                limits = value;
                OnPropertyChanged(nameof(Limits));
            }
        }
        public List<KeyAndValueDto> ModuleTypes => TypeExtension.ToKeyAndDescriptionList(typeof(ModuleType));

        public event PropertyChangedEventHandler PropertyChanged;
        protected internal virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    public class TcpDataModel : INotifyPropertyChanged
    {
        private string ipAddress;
        private int port;
        private byte station;
        public string IpAddress
        {
            get => ipAddress;
            set
            {
                ipAddress = value;
                OnPropertyChanged(nameof(IpAddress));
            }
        }
        public int Port
        {
            get => port;
            set
            {
                port = value;
                OnPropertyChanged(nameof(Port));
            }
        }
        public byte Station
        {
            get => station;
            set
            {
                station = value;
                OnPropertyChanged(nameof(Station));
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        protected internal virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    public class SerialDataModel : INotifyPropertyChanged
    {
        private string portName;
        private int baudRate;
        private int dataBits;
        private string parity;
        private int stopBits;
        private byte station;
        public string PortName
        {
            get => portName;
            set
            {
                portName = value;
                OnPropertyChanged(nameof(PortName));
            }
        }
        public int BaudRate
        {
            get => baudRate;
            set
            {
                baudRate = value;
                OnPropertyChanged(nameof(BaudRate));
            }
        }
        public int DataBits
        {
            get => dataBits;
            set
            {
                dataBits = value;
                OnPropertyChanged(nameof(DataBits));
            }
        }
        public string Parity
        {
            get => parity;
            set
            {
                parity = value;
                OnPropertyChanged(nameof(Parity));
            }
        }
        public int StopBits
        {
            get => stopBits;
            set
            {
                stopBits = value;
                OnPropertyChanged(nameof(StopBits));
            }
        }
        public byte Station
        {
            get => station;
            set
            {
                station = value;
                OnPropertyChanged(nameof(Station));
            }
        }
        public List<string> SerialNames => SerialPort.GetPortNames().ToList();
        public event PropertyChangedEventHandler PropertyChanged;
        protected internal virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    public class LimitDataModel : INotifyPropertyChanged
    {
        private string name;
        private string address;
        private double position;
        private bool isReverse;
        private bool isEnable;
        private List<RopeDataModel> relatedRopes;
        public string Name
        {
            get => name;
            set
            {
                name = value;
                OnPropertyChanged(nameof(Name));
            }
        }
        public string Address
        {
            get => address;
            set
            {
                address = value;
                OnPropertyChanged(nameof(Address));
            }
        }
        public double Position
        {
            get => position;
            set
            {
                position = value;
                OnPropertyChanged(nameof(Position));
            }
        }
        public bool IsReverse
        {
            get => isReverse;
            set
            {
                isReverse = value;
                OnPropertyChanged(nameof(IsReverse));
            }
        }
        public bool IsEnable
        {
            get => isEnable;
            set
            {
                isEnable = value;
                OnPropertyChanged(nameof(IsEnable));
            }
        }
        public List<RopeDataModel> RelatedRopes
        {
            get => relatedRopes;
            set
            {
                relatedRopes = value;
                OnPropertyChanged(nameof(RelatedRopes));
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        protected internal virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    public class RopeDataModel : INotifyPropertyChanged
    {
        private int ropeNumber;
        private string ropeName;
        private bool isSelected;
        public int RopeNumber
        {
            get => ropeNumber;
            set
            {
                ropeNumber = value;
                OnPropertyChanged(nameof(RopeNumber));
            }
        }
        public string RopeName
        {
            get => ropeName;
            set
            {
                ropeName = value;
                OnPropertyChanged(nameof(RopeName));
            }
        }
        public bool IsSelected
        {
            get => isSelected;
            set
            {
                isSelected = value;
                OnPropertyChanged(nameof(IsSelected));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected internal virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
