using DeviceRepair.Models.Attr;
using DeviceRepair.Models.Enum;
using Newtonsoft.Json;
using System.Linq;
using TsSFCDevice.Client.Biz.Base.Utils;

namespace TsSFCDevice.Client.Biz.His
{
    public class DevOpsHistory
    {
        [JsonProperty("Operator", NullValueHandling = NullValueHandling.Ignore)]
        public int Operator
        {
            get;
            set;
        }

        /// <summary>
        /// 名称
        /// </summary>
        [HistoryFilterField(Code = "EquipmentID", CtlType = HistoryFilterCtlType.TextBox, DefaultValue = "", Description = "设备编号", ShowSequence = 1)]
        [HistoryGridField(Description = "设备编号", ShowSequence = 1)]
        [JsonProperty("EquipmentID", NullValueHandling = NullValueHandling.Ignore)]
        public string EquipmentID { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [HistoryGridField(Description = "设备名称", ShowSequence = 2)]
        [HistoryFilterField(Code = "EquipmentName", CtlType = HistoryFilterCtlType.TextBox, DefaultValue = "", Description = "设备名称", ShowSequence = 2)]
        [JsonProperty("EquipmentName", NullValueHandling = NullValueHandling.Ignore)]
        public string EquipmentName { get; set; }

        [HistoryGridField(Description = "操作类型", ShowSequence = 3)]
        [JsonProperty("OperationType", NullValueHandling = NullValueHandling.Ignore)]
        public string OperationType
        {
            get;
            set;
        } 

        [HistoryGridField(Description = "操作人", ShowSequence = 4)]
        [JsonProperty("OperatorName", NullValueHandling = NullValueHandling.Ignore)]
        public string OperatorName
        {
            get
            {
                var us = Utility.SystemRuntimeInfo.CurrentUsersCaches.FirstOrDefault(x => x.Id == Operator);
                return (us?.UserCode) ?? "N/A";
            }
        }

        [HistoryGridField(Description = "操作时间", ShowSequence = 5)]
        [JsonProperty("OperationDate", NullValueHandling = NullValueHandling.Ignore)]
        public string OperationDate
        {
            get;
            set;
        }


        [HistoryGridField(Description = "操作客户端", ShowSequence = 6)]
        [JsonProperty("OperationComputer", NullValueHandling = NullValueHandling.Ignore)]
        public string OperationComputer
        {
            get;
            set;
        }
    }
}
