using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UIShare.UIViewModel
{
    /// <summary>
    /// 串口连接配置（与 DeviceCommand.Base.Serial_Port 保持字段一致）。
    /// StopBits / Parity 用字符串保存，避免 UIShare 引入 System.IO.Ports 依赖。
    /// </summary>
    public class SerialPortConfigVM : BindableBase
    {
        private string _portName = "COM1";
        public string PortName
        {
            get => _portName;
            set => SetProperty(ref _portName, value);
        }

        private int _baudRate = 9600;
        public int BaudRate
        {
            get => _baudRate;
            set => SetProperty(ref _baudRate, value);
        }

        private int _dataBits = 8;
        public int DataBits
        {
            get => _dataBits;
            set => SetProperty(ref _dataBits, value);
        }

        // 取值："One" / "OnePointFive" / "Two" / "None"
        private string _stopBits = "One";
        public string StopBits
        {
            get => _stopBits;
            set => SetProperty(ref _stopBits, value);
        }

        // 取值："None" / "Odd" / "Even" / "Mark" / "Space"
        private string _parity = "None";
        public string Parity
        {
            get => _parity;
            set => SetProperty(ref _parity, value);
        }

        private int _readTimeout = 3000;
        public int ReadTimeout
        {
            get => _readTimeout;
            set => SetProperty(ref _readTimeout, value);
        }

        private int _writeTimeout = 3000;
        public int WriteTimeout
        {
            get => _writeTimeout;
            set => SetProperty(ref _writeTimeout, value);
        }

        public SerialPortConfigVM() { }

        public SerialPortConfigVM(SerialPortConfigVM? src)
        {
            if (src == null) return;
            PortName = src.PortName;
            BaudRate = src.BaudRate;
            DataBits = src.DataBits;
            StopBits = src.StopBits;
            Parity = src.Parity;
            ReadTimeout = src.ReadTimeout;
            WriteTimeout = src.WriteTimeout;
        }

        public void CopyTo(SerialPortConfigVM? dst)
        {
            if (dst == null) return;
            dst.PortName = PortName;
            dst.BaudRate = BaudRate;
            dst.DataBits = DataBits;
            dst.StopBits = StopBits;
            dst.Parity = Parity;
            dst.ReadTimeout = ReadTimeout;
            dst.WriteTimeout = WriteTimeout;
        }
    }
}
