using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FObjBase;
using FLY.Thick.Base.Common;

namespace FLY.Thick.Base.OBJ_INTERFACE
{
    public class WARNING_OBJ_INTERFACE
    {
        public const UInt32 ID = OBJ_INTERFACE_ID.WARNING_ID;
        #region Pack
        public class Pack_Params : IPack
        {
            public int outIdxOfWarning;
            public int duration;
            public bool enable;
            public bool enSave;
            public int[] whitelist;
            public int[] blacklist;

            /// <summary>
            /// 转换为8个bytes
            /// </summary>
            /// <returns></returns>
            public byte[] ToBytes()
            {
                List<byte> buf = new List<byte>();

                buf.AddRange(BitConverter.GetBytes(outIdxOfWarning));
                buf.AddRange(BitConverter.GetBytes(duration));
                buf.AddRange(BitConverter.GetBytes(enable));
                buf.AddRange(BitConverter.GetBytes(enSave));
                buf.AddRange(BitConverter.GetBytes(whitelist.Count()));
                for (int i = 0; i < whitelist.Count(); i++)
                {
                    buf.AddRange(BitConverter.GetBytes(whitelist[i]));
                }
                buf.AddRange(BitConverter.GetBytes(whitelist.Count()));
                for (int i = 0; i < blacklist.Count(); i++)
                {
                    buf.AddRange(BitConverter.GetBytes(blacklist[i]));
                }
                
                return buf.ToArray();
            }
            /// <summary>
            /// 由8个bytes 转换为 CustomBolt
            /// </summary>
            /// <param name="value"></param>
            /// <returns></returns>
            public bool TryParse(byte[] value)
            {
                if (value.Length < (4 + 4 + 1 + 1 + 4 + 4))
                    return false;
                int idx = 0;
                outIdxOfWarning = BitConverter.ToInt32(value, idx);
                idx += 4;
                duration = BitConverter.ToInt32(value, idx);
                idx += 4;
                enable = BitConverter.ToBoolean(value, idx);
                idx++;
                enSave = BitConverter.ToBoolean(value, idx);
                idx++;
                int len;
                len = BitConverter.ToInt32(value, idx);
                idx += 4;
                if (value.Length < (4 + 4 + 1 + 1 + 4 + 4+len))
                    return false;
                whitelist = new int[len];
                for (int i = 0; i < len; i++)
                {
                    whitelist[i] = BitConverter.ToInt32(value, idx);
                    idx += 4;
                }

                int len2;
                len2 = BitConverter.ToInt32(value, idx);
                idx += 4;
                if (value.Length < (4 + 4 + 1 + 1 + 4 + 4 + len+len2))
                    return false;
                blacklist = new int[len2];
                for (int i = 0; i < len2; i++)
                {
                    blacklist[i] = BitConverter.ToInt32(value, idx);
                    idx += 4;
                }

                return true;
            }
        }
        public class Pack_ReasonList : IPack
        {
            public FlyData_WarningHistory[] list;

            #region IPack 成员

            public byte[] ToBytes()
            {
                List<byte> buf = new List<byte>();

                buf.AddRange(BitConverter.GetBytes(list.Count()));
                for (int i = 0; i < list.Count(); i++)
                {
                    buf.AddRange(list[i].ToBytes());
                }
                return buf.ToArray();
            }

            public bool TryParse(byte[] value)
            {
                int cnt = 4;
                if (value.Length < cnt)
                    return false;

                int idx = 0;
                int len = BitConverter.ToInt32(value, idx);
                idx += 4;
                cnt += len * 14;
                if (value.Length < cnt)
                    return false;

                list = new FlyData_WarningHistory[len];
                for (int i = 0; i < len; i++)
                {
                    int c;
                    list[i] = new FlyData_WarningHistory();
                    if (!list[i].TryParse(value, idx, out c))
                        return false;
                    idx += c;
                }
                return true;
            }
            #endregion

        }

        #endregion

        #region GetValue
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 GET_PARAMS = 0;
        /// <summary>
        /// Pack_ReasonList
        /// </summary>
        public const UInt16 GET_REASONLIST = 1;
        /// <summary>
        /// FlyData_WarningHistory
        /// </summary>
        public const UInt16 GET_CURR = 2;
        #endregion
        #region SetValue
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 SET_PARAMS = 0;
        #endregion
        #region PushMsg
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 PUSH_PARAMS = 0;
        public const UInt16 PUSH_REASONLIST = 1;
        public const UInt16 PUSH_CURR = 2;
        #endregion
        #region CallFunction
        public const UInt16 CALL_RESET = 0;
        /// <summary>
        /// FlyData_WarningHistory
        /// </summary>
        public const UInt16 CALL_ADD = 1;

        public const UInt16 CALL_QUIET= 2;
        #endregion
    }

}
