using System;
using System.Runtime.Serialization;
using SqlSugar;

namespace WCS.Entity.Protocol.HUB
{
    /// <summary>
    ///     设备运行信息
    /// </summary>
    [DataContract]
    [SugarTable("SX_DevRunInfo")]
    public class DevRunInfo : QuestDBBaseEntity
    {
        public DevRunInfo()
        {
        }

        /// <summary>
        /// </summary>
        /// <param name="runMode"></param>
        /// <param name="runStatus"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="duration"></param>
        /// <param name="type"></param>
        /// <param name="code"></param>
        /// <param name="frame"></param>
        public DevRunInfo(string runMode, string runStatus, DateTime startTime, DateTime endTime, long duration,
            string type, string code, DateTime frame)
        {
            RunMode = runMode;
            RunStatus = runStatus;
            StartTime = startTime;
            EndTime = endTime;
            Duration = duration;
            Type = type;
            Code = code;
            Frame = frame;
        }

        /// <summary>
        ///     运行模式
        /// </summary>
        [SugarColumn(ColumnDataType = "symbol")]
        public string RunMode { get; set; }

        /// <summary>
        ///     运行状态
        /// </summary>
        [SugarColumn(ColumnDataType = "symbol")]
        public string RunStatus { get; set; }

        /// <summary>
        ///     开始时间
        /// </summary>

        public DateTime StartTime { get; set; }

        /// <summary>
        ///     结束时间
        /// </summary>

        public DateTime EndTime { get; set; }

        /// <summary>
        ///     总时长
        /// </summary>
        public long Duration { get; set; }

        /// <summary>
        ///     类型
        /// </summary>
        [SugarColumn(ColumnDataType = "symbol")]
        public string Type { get; set; }

        /// <summary>
        ///  获取起始地址
        /// </summary>
        /// <param name="workstation"></param>
        /// <returns></returns>
        public string GetStartAddress(int workstation)
        {
            return workstation switch
            {
                1 => ExtraField1.Split("|")[0],
                2 => ExtraField2.Split("|")[0],
                _ => throw new Exception("请选择工位")
            };
        }

        /// <summary>
        ///  获取目标地址
        /// </summary>
        /// <param name="workstation"></param>
        /// <returns></returns>
        public string GetTargetAddress(int workstation)
        {
            return workstation switch
            {
                1 => ExtraField1.Split("|")[1],
                2 => ExtraField2.Split("|")[1],
                _ => throw new Exception("请选择工位")
            };
        }
    }

    public enum DevType
    {
        /// <summary>
        ///     RGV小车
        /// </summary>
        RGV = 1,

        /// <summary>
        ///     堆垛机
        /// </summary>
        SRM = 2,

        /// <summary>
        ///     机械臂/机器人
        /// </summary>
        Robot = 3,

        /// <summary>
        ///     桁架
        /// </summary>
        Truss = 4,

        /// <summary>
        ///     扫码器
        /// </summary>
        BCR = 5,

        /// <summary>
        ///     站台/输送线
        /// </summary>
        Station = 6,

        /// <summary>
        ///     机械臂/机器人 任务执行数量
        /// </summary>
        RobotTaskSum = 7,

        /// <summary>
        ///     桁架 任务执行数量
        /// </summary>
        TrussTaskSum = 8,

        /// <summary>
        ///     来料统计
        /// </summary>
        FeedRate = 9,

        /// <summary>
        ///  状态统计
        /// </summary>
        RunStatus = 10,

        /// <summary>
        ///  侧推任务统计
        /// </summary>
        线体状态统计 = 11,

        /// <summary>
        ///  堆垛机任务数量统计
        /// </summary>
        SrmTaskSum=12,
    }
}