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

namespace NEIntelligentControl2.Models.Alarm
{

    /// <summary>
    /// 故障信息
    /// </summary>
    public class FaultInfo
    {
        /// <summary>
        /// 故障信息ID
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 报警时间
        /// </summary>
        public DateTime? FaultTime { get; set; }

        /// <summary>
        /// 对象类型
        /// </summary>
        public int MessageType { get; set; }

        /// <summary>
        /// 发送缺陷单使用   这个表的FaultSnap.id
        /// </summary>
        public long SnapID { get; set; }
        /// <summary>
        /// 确认类型
        /// </summary>
        public int ConfirmType { get; set; }
        /// <summary>
        /// 确认时间
        /// </summary>
        public DateTime? ConfirmTime { get; set; }
        /// <summary>
        /// 确认人
        /// </summary>
        public string ConfirmPerson { get; set; }
        /// <summary>
        /// 场站ID
        /// </summary>
        public string StationId { get; set; }
        /// <summary>
        /// ProjectID
        /// </summary>
        public string ProjectId { get; set; }
        /// <summary>
        /// LineID
        /// </summary>
        public string LineId { get; set; }
        /// <summary>
        /// 风机ID
        /// </summary>
        public string WindturbineId { get; set; }

        /// <summary>
        /// 报警对应故障编码
        /// </summary>
        public long AlertValue { get; set; }

        /// <summary>
        /// 报警级别
        /// </summary>
        public string Rank { get; set; }

        /// <summary>
        /// 类型1
        /// </summary>
        public string Category1 { get; set; }

        /// <summary>
        /// 类型2
        /// </summary>
        public string Category2 { get; set; }

        /// <summary>
        /// 类型3
        /// </summary>
        public string Category3 { get; set; }

        /// <summary>
        /// 是否活跃
        /// </summary>
        [JsonPropertyName("opened")]
        public bool IsOpened { get; set; }

        /// <summary>
        /// 最新更新时间
        /// </summary>
        public DateTime? LastUpdateTime { get; set; }

        /// <summary>
        /// 最新更新人
        /// </summary>
        public string LastUpdatePerson { get; set; }

        /// <summary>
        /// 场站名称
        /// </summary>
        public string StationName { get; set; }

        /// <summary>
        /// ProjectName
        /// </summary>
        public string ProjectName { get; set; }

        /// <summary>
        /// LineName
        /// </summary>
        public string LineName { get; set; }

        /// <summary>
        /// 风机名称
        /// </summary>
        public string WindturbineName { get; set; }

        /// <summary>
        /// 报警信息
        /// </summary>
        public string AlertText { get; set; }

        /// <summary>
        /// 风机类型ID
        /// </summary>
        public string ModelId { get; set; }
        /// <summary>
        /// 报警设备名称
        /// </summary>
        public string ObjectName { get; set; }
        /// <summary>
        /// 报警设备id
        /// </summary>
        public string ObjectId { get; set; }

        /// <summary>
        /// 报警设备类型名称
        /// </summary>
        public string CategoryName { get; set; }
        /// <summary>
        /// 解除触发
        /// </summary>
        public string MessageTypeString { get; set; }

        /// <summary>
        /// 是否可以复位
        /// </summary>
        public bool IsAllowReset { get; set; }

        public string LatestUpdateTimeString
        {
            get
            {
                if (FaultTime != null)
                {
                    return FaultTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                }
                return LastUpdateTime?.ToString("yyyy-MM-dd HH:mm:ss");
            }
        }
        private string objectName;
        public string ObjectNameString
        {
            set => objectName = value;
            get
            {
                if (objectName != null) return objectName;
                if (Category1 == "SYZ" || Category1 == "STATION" || Category1 == "GF")
                {
                    return StationName;
                }
                return WindturbineName;
            }
        }
    }
}
