using SQLite;
using System;

namespace FLY.OBJComponents.Common
{
    /// <summary>
    /// 数据库的 ERROR
    /// </summary>
    public class FlyData_WarningHistory : IDbBase
    {
        /// <summary>
        /// ID
        /// </summary>
        public Int64 ID { get; set; }
        /// <summary>
        /// 时间
        /// </summary>
        public DateTime Time { get; set; }

        /// <summary>
        /// 出错码
        /// </summary>
        public int ErrCode { get; set; }
        /// <summary>
        /// 出错状态
        /// </summary>
        public ERR_STATE State { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }
        /// <summary>
        /// 附加信息， json格式
        /// </summary>
        public string Accessory { get; set; }

        /// <summary>
        /// 可以被复位
        /// </summary>
        public bool CanReset { get; set; } = true;


        public FlyData_WarningHistory Clone()
        {
            return new FlyData_WarningHistory()
            {
                Time = Time,
                ErrCode = ErrCode,
                State = State,
                Description = Description,
                Accessory = Accessory,
                ID = ID,
                CanReset = CanReset
            };
        }

        public override string ToString()
        {
            string str;
            str = Time.ToString();
            str += "," + ErrCode.ToString();
            str += "," + State.ToString();
            str += "," + Description;
            if (!string.IsNullOrEmpty(Accessory))
                str += "," + Accessory;
            return str;
        }
    }

    /// <summary>
    /// 报警状态
    /// </summary>
    public enum ERR_STATE
    {
        /// <summary>
        /// 报警中
        /// </summary>
        ON,
        /// <summary>
        /// 关闭
        /// </summary>
        OFF
    }

    /// <summary>
    /// 出错类型
    /// </summary>
    public struct ERRNO
    {
        public int Code;
        public string Description;
        public override string ToString()
        {
            return $"[{Code}] {Description}";
        }
    }

    public class PlcErrNos
    {
        public static PlcErrNos Instance { get; } = new PlcErrNos();

        /// <summary>
        /// PLC连接断开
        /// </summary>
        public ERRNO ERRNO_PLC_DISCONNECTED = new ERRNO() { Code = 65535, Description = "PLC连接断开" };
    }
}
