using OpenTK.Graphics.ES20;
using SWRIS.Dtos;
using SWRIS.Enums;
using SWRIS.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace SWRIS.Models.ViewModel
{
    public class EquipmentSettingViewModel : INotifyPropertyChanged
    {
        private int ropeNumber;
        private string ropeName;
        private string ipAddress;
        private string serialNo;
        private string supplier;
        private int ropeCoreType;
        private int wireMaterialType;
        private int wireSurfaceType;
        private int layType;
        private bool disableAlarm;
        private int[] inUseSensor = new int[] { 1, 2, 3, 4 };
        private double liftHightRatio = 1;
        private RiskLevel soundRiskLevel = RiskLevel.Moderate;
        private ParameterData parameter;
        private bool isConnected;
        /// <summary>
        /// 绳号
        /// </summary>
        public int RopeNumber
        {
            get { return ropeNumber; }
            set
            {
                ropeNumber = value;
                OnPropertyChanged(nameof(RopeNumber));
            }
        }
        /// <summary>
        /// 钢丝绳名称
        /// </summary>
        public string RopeName
        {
            get { return ropeName; }
            set
            {
                ropeName = value;
                OnPropertyChanged(nameof(RopeName));
            }
        }
        /// <summary>
        /// Ip地址
        /// </summary>
        public string IpAddress
        {
            get { return ipAddress; }
            set
            {
                ipAddress = value;
                OnPropertyChanged(nameof(IpAddress));
            }
        }
        /// <summary>
        /// 序列号
        /// </summary>
        public string SerialNo
        {
            get { return serialNo; }
            set
            {
                serialNo = value;
                OnPropertyChanged(nameof(SerialNo));
            }
        }
        /// <summary>
        /// 供应商
        /// </summary>
        public string Supplier
        {
            get { return supplier; }
            set
            {
                supplier = value;
                OnPropertyChanged(nameof(Supplier));
            }
        }
        /// <summary>
        /// 绳芯类型 1 钢芯 2 纤维芯
        /// </summary>
        public int RopeCoreType
        {
            get { return ropeCoreType; }
            set
            {
                ropeCoreType = value;
                OnPropertyChanged(nameof(RopeCoreType));
            }
        }
        /// <summary>
        /// 钢丝材质 1 碳钢 2 不锈钢
        /// </summary>
        public int WireMaterialType
        {
            get { return wireMaterialType; }
            set
            {
                wireMaterialType = value;
                OnPropertyChanged(nameof(WireMaterialType));
            }
        }
        /// <summary>
        /// 表面状态 1 光面 2 A级镀锌 3 B级镀锌 
        /// </summary>
        public int WireSurfaceType
        {
            get { return wireSurfaceType; }
            set
            {
                wireSurfaceType = value;
                OnPropertyChanged(nameof(WireSurfaceType));
            }
        }
        /// <summary>
        /// 捻向 1 右交互捻 2 左交互捻 3 右同向捻 4 左同向捻
        /// </summary>
        public int LayType
        {
            get { return layType; }
            set
            {
                layType = value;
                OnPropertyChanged(nameof(LayType));
            }
        }
        /// <summary>
        /// 绳长/高度倍率
        /// </summary>
        public double LiftHightRatio
        {

            get { return liftHightRatio; }
            set
            {
                liftHightRatio = value;
                OnPropertyChanged(nameof(LiftHightRatio));
            }
        }
        public RiskLevel SoundRiskLevel
        {
            get { return soundRiskLevel; }
            set
            {
                soundRiskLevel = value;
                OnPropertyChanged(nameof(SoundRiskLevel));
            }
        }
        public ParameterData Parameter
        {
            get { return parameter; }
            set
            {
                parameter = value;
                OnPropertyChanged(nameof(Parameter));
            }
        }
        public bool IsConnected
        {
            get { return isConnected; }
            set
            {
                isConnected = value;
                OnPropertyChanged(nameof(IsConnected));
            }
        }
        public bool DisableAlarm
        {
            get { return disableAlarm; }
            set
            {
                disableAlarm = value;
                OnPropertyChanged(nameof(DisableAlarm));
            }
        }
        public int[] InUseSensor
        {
            get { return inUseSensor; }
            set
            {
                inUseSensor = value;
                OnPropertyChanged(nameof(InUseSensor));
            }
        }
        public List<KeyAndValueDto> RopeCoreTypes => TypeExtension.ToKeyAndDescriptionList(typeof(RopeCoreType));
        public List<KeyAndValueDto> WireMaterialTypes => TypeExtension.ToKeyAndDescriptionList(typeof(WireMaterialType));
        public List<KeyAndValueDto> LayTypes => TypeExtension.ToKeyAndDescriptionList(typeof(LayType));
        public List<KeyAndValueDto> WireSurfaceTypes => TypeExtension.ToKeyAndDescriptionList(typeof(WireSurfaceType));
        public List<KeyAndValueDto> RiskLevels => TypeExtension.ToKeyAndDescriptionList(typeof(RiskLevel));

        public event PropertyChangedEventHandler PropertyChanged;
        protected internal virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    public class ParameterData : INotifyPropertyChanged
    {
        private string mainBoardSoftwareVersion;
        private short sensorCount;
        private float samplingStep;
        private short frequencyDivisionFactor;
        private short timeDomainFrequency;
        private short damageThreshold;
        private short scrapUpperLimit;
        private short frontMagnetLength;
        private short backMagnetLength;
        private float valueCoefficient;
        private float effectiveStrokeLength;
        private short zeroPositionCorrectionDuration;
        private short zeroPositionCorrectionOffset;
        private float warningValue;
        private float alarmValue;
        private short soundLightAlarmAutoResetMode;
        private short wireRopeType;
        private short wireRopeCount;
        private float wireRopeLength;
        private float wireRopeDiameter;
        private short wireRopeStrandCount;
        private short wireRopeStrandWireCount;
        private EncoderDirection encoderDirection;
        private DateTime? systemTime;
        private float twistFactor;

        /// <summary>
        /// 主板软件版本号
        /// </summary>
        public string MainBoardSoftwareVersion
        {
            get => mainBoardSoftwareVersion;
            set
            {
                mainBoardSoftwareVersion = value;
                OnPropertyChanged(nameof(MainBoardSoftwareVersion));
            }
        }
        /// <summary>
        /// 传感器数量
        /// </summary>
        public short SensorCount
        {
            get => sensorCount;
            set
            {
                sensorCount = value;
                OnPropertyChanged(nameof(SensorCount));
            }
        }
        /// <summary>
        /// 采样步长 单位：mm/点   4字节浮点数
        /// </summary>
        public float SamplingStep
        {
            get => samplingStep;
            set
            {
                samplingStep = value;
                OnPropertyChanged(nameof(SamplingStep));
            }
        }
        /// <summary>
        /// 分频系数
        /// </summary>
        public short FrequencyDivisionFactor
        {
            get => frequencyDivisionFactor;
            set
            {
                frequencyDivisionFactor = value;
                OnPropertyChanged(nameof(FrequencyDivisionFactor));
            }
        }
        /// <summary>
        /// 时域频率  2字节整型
        /// </summary>
        public short TimeDomainFrequency
        {
            get => timeDomainFrequency;
            set
            {
                timeDomainFrequency = value;
                OnPropertyChanged(nameof(TimeDomainFrequency));
            }
        }
        /// <summary>
        /// 损伤门限   2字节整型
        /// </summary>
        public short DamageThreshold
        {
            get => damageThreshold;
            set
            {
                damageThreshold = value;
                OnPropertyChanged(nameof(DamageThreshold));
            }
        }
        /// <summary>
        /// 报废上限
        /// </summary>
        public short ScrapUpperLimit
        {
            get => scrapUpperLimit;
            set
            {
                scrapUpperLimit = value;
                OnPropertyChanged(nameof(ScrapUpperLimit));
            }
        }
        /// <summary>
        /// 前磁极长度  单位：mm  2字节整型
        /// </summary>
        public short FrontMagnetLength
        {
            get => frontMagnetLength;
            set
            {
                frontMagnetLength = value;
                OnPropertyChanged(nameof(FrontMagnetLength));
            }
        }
        /// <summary>
        /// 后磁极长度  单位：mm  2字节整型
        /// </summary>
        public short BackMagnetLength
        {
            get => backMagnetLength;
            set
            {
                backMagnetLength = value;
                OnPropertyChanged(nameof(BackMagnetLength));
            }
        }
        /// <summary>
        /// 量值系数  4字节浮点数
        /// </summary>
        public float ValueCoefficient
        {
            get => valueCoefficient;
            set
            {
                valueCoefficient = value;
                OnPropertyChanged(nameof(ValueCoefficient));
            }
        }
        /// <summary>
        /// 零位有效行程长度，单位：m  4字节浮点数
        /// </summary>
        public float EffectiveStrokeLength
        {
            get => effectiveStrokeLength;
            set
            {
                effectiveStrokeLength = value;
                OnPropertyChanged(nameof(EffectiveStrokeLength));
            }
        }
        /// <summary>
        /// 零位矫正静止时长，单位：秒  2字节整型
        /// </summary>
        public short ZeroPositionCorrectionDuration
        {
            get => zeroPositionCorrectionDuration;
            set
            {
                zeroPositionCorrectionDuration = value;
                OnPropertyChanged(nameof(ZeroPositionCorrectionDuration));
            }
        }
        /// <summary>
        /// 零位矫正允许偏移量，单位：mm  2字节整型
        /// </summary>
        public short ZeroPositionCorrectionOffset
        {
            get => zeroPositionCorrectionOffset;
            set
            {
                zeroPositionCorrectionOffset = value;
                OnPropertyChanged(nameof(ZeroPositionCorrectionOffset));
            }
        }
        /// <summary>
        /// 预警（黄色报警）量值  4字节浮点数
        /// </summary>
        public float WarningValue
        {
            get => warningValue;
            set
            {
                warningValue = value;
                OnPropertyChanged(nameof(WarningValue));
            }
        }
        /// <summary>
        /// 报警（红色报警）量值  4字节浮点数
        /// </summary>
        public float AlarmValue
        {
            get => alarmValue;
            set
            {
                alarmValue = value;
                OnPropertyChanged(nameof(AlarmValue));
            }
        }
        /// <summary>
        /// 声光报警自动重置方式，0=不自动重置，>0=延时自动重置，-1=开始新一次检测时重置
        /// </summary>
        public short SoundLightAlarmAutoResetMode
        {
            get => soundLightAlarmAutoResetMode;
            set
            {
                soundLightAlarmAutoResetMode = value;
                OnPropertyChanged(nameof(SoundLightAlarmAutoResetMode));
            }
        }
        /// <summary>
        /// 钢丝绳类型 0=塔吊单绳，1=电梯排绳
        /// </summary>
        public short WireRopeType
        {
            get => wireRopeType;
            set
            {
                wireRopeType = value;
                OnPropertyChanged(nameof(WireRopeType));
            }
        }
        /// <summary>
        ///钢丝绳数量 1字节
        /// </summary>
        public short WireRopeCount
        {
            get => wireRopeCount;
            set
            {
                wireRopeCount = value;
                OnPropertyChanged(nameof(WireRopeCount));
            }
        }
        /// <summary>
        /// 钢丝绳长度，单位：m  4字节浮点数
        /// </summary>
        public float WireRopeLength
        {
            get => wireRopeLength;
            set
            {
                wireRopeLength = value;
                OnPropertyChanged(nameof(WireRopeLength));
            }
        }
        /// <summary>
        /// 钢丝绳直径，单位：mm  4字节浮点数
        /// </summary>
        public float WireRopeDiameter
        {
            get => wireRopeDiameter;
            set
            {
                wireRopeDiameter = value;
                OnPropertyChanged(nameof(WireRopeDiameter));
            }
        }
        /// <summary>
        /// 钢丝绳股数 1字节
        /// </summary>
        public short WireRopeStrandCount
        {
            get => wireRopeStrandCount;
            set
            {
                wireRopeStrandCount = value;
                OnPropertyChanged(nameof(WireRopeStrandCount));
            }
        }
        /// <summary>
        /// 钢丝绳每股丝数，2字节整型
        /// </summary>
        public short WireRopeStrandWireCount
        {
            get => wireRopeStrandWireCount;
            set
            {
                wireRopeStrandWireCount = value;
                OnPropertyChanged(nameof(WireRopeStrandWireCount));
            }
        }
        /// <summary>
        /// 编码器方向，1=正向，2=反向
        /// </summary>
        public EncoderDirection EncoderDirection
        {
            get => encoderDirection;
            set
            {
                encoderDirection = value;
                OnPropertyChanged(nameof(EncoderDirection));
            }
        }
        /// <summary>
        /// 系统时间
        /// </summary>
        public DateTime? SystemTime
        {
            get => systemTime;
            set
            {
                systemTime = value;
                OnPropertyChanged(nameof(SystemTime));
            }
        }
        /// <summary>
        /// 判伤捻距系数，浮点数，判伤捻距默认为7d，可通过此参数设置系数来调整（与损伤判定相关）。
        /// 默认值为1.0，设置2.0表示判伤捻距为2 x 7 = 14d
        /// </summary>
        public float TwistFactor
        {
            get => twistFactor;
            set
            {
                twistFactor = value;
                OnPropertyChanged(nameof(TwistFactor));
            }
        }

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