using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FObjBase;

namespace FLY.Thick.Base.OBJ_INTERFACE
{
    public class REJECT_OBJ_INTERFACE
    {
        #region Pack
        public class Pack_Params : IPack
        {
            public bool enable;
            public double threshold_ratio;
            public bool ispercent;
            public double psigma;
            public int sigma;
            public int range1;
            public int range2;
            

            #region IPack 成员

            public byte[] ToBytes()
            {
                List<byte> buf = new List<byte>();
                buf.AddRange(BitConverter.GetBytes(enable));
                buf.AddRange(BitConverter.GetBytes(threshold_ratio));
                buf.AddRange(BitConverter.GetBytes(ispercent));
                buf.AddRange(BitConverter.GetBytes(psigma));
                buf.AddRange(BitConverter.GetBytes(sigma));
                buf.AddRange(BitConverter.GetBytes(range1));
                buf.AddRange(BitConverter.GetBytes(range2));

                return buf.ToArray();
            }

            public bool TryParse(byte[] value)
            {
                if (value.Length < (1 + 8 + 1 + 8 + 4*3))
                    return false;

                int index = 0;
                enable = BitConverter.ToBoolean(value, index);
                index += 1;
                threshold_ratio = BitConverter.ToDouble(value, index);
                index += 8;
                ispercent = BitConverter.ToBoolean(value, index);
                index += 1;
                psigma = BitConverter.ToDouble(value, index);
                index += 8;
                sigma = BitConverter.ToInt32(value, index);
                index += 4;
                range1 = BitConverter.ToInt32(value, index);
                index += 4;
                range2 = BitConverter.ToInt32(value, index);
                index += 4;
                return true;
            }

            #endregion
        }
        public class Pack_PosInfo : IPack
        {
            public int posofgrid;
            public int poslen;
            public int target;
            #region IPack 成员

            public byte[] ToBytes()
            {
                List<byte> buf = new List<byte>();
                buf.AddRange(BitConverter.GetBytes(posofgrid));
                buf.AddRange(BitConverter.GetBytes(poslen));
                buf.AddRange(BitConverter.GetBytes(target));
                return buf.ToArray();
            }

            public bool TryParse(byte[] value)
            {
                if (value.Length < 12)
                    return false;
                int index = 0;
                posofgrid = BitConverter.ToInt32(value, index);
                index += 4;
                poslen = BitConverter.ToInt32(value, index);
                index += 4;
                target = BitConverter.ToInt32(value, index);
                index += 4;
                return true;
            }

            #endregion

        }
        public class Pack_Data : IPack
        {
            public int[] data;

            public byte[] ToBytes()
            {
                List<byte> buf = new List<byte>();
                buf.AddRange(BitConverter.GetBytes(data.Length));
                for (int i = 0; i < data.Length; i++)
                {
                    buf.AddRange(BitConverter.GetBytes(data[i]));
                }
                return buf.ToArray();
            }

            public bool TryParse(byte[] value)
            {
                if (value.Length < 4)
                    return false;
                int index = 0;
                int len = BitConverter.ToInt32(value, index);
                index += 4;
                if (value.Length < (len * 4 + 4))
                    return false;

                data = new int[len];
                for (int i = 0; i < len; i++)
                {
                    data[i] = BitConverter.ToInt32(value, index);
                    index += 4;
                }

                return true;
            }
        }
        #endregion
        #region GetValue
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 GET_PARAMS = 1;
        /// <summary>
        /// Pack_PosInfo
        /// </summary>
        public const UInt16 GET_POSINFO = 2;
        /// <summary>
        /// Pack_Data
        /// </summary>
        public const UInt16 GET_FILTERDATAS = 3;
        /// <summary>
        /// Pack_Data
        /// </summary>
        public const UInt16 GET_REJECTDATAS = 4;
        /// <summary>
        /// Pack_Data
        /// </summary>
        public const UInt16 GET_SIGMADATAS = 5;

        #endregion

        #region SetValue
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 SET_PARAMS = 1;
        #endregion

        #region CallFunction

        #endregion
        #region PushInfo
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 PUSH_PARAMS = 1;
        /// <summary>
        /// Pack_PosInfo
        /// </summary>
        public const UInt16 PUSH_POSINFO = 2;
        /// <summary>
        /// Pack_Data
        /// </summary>
        public const UInt16 PUSH_FILTERDATAS = 3;
        /// <summary>
        /// Pack_Data
        /// </summary>
        public const UInt16 PUSH_REJECTDATAS = 4;
        /// <summary>
        /// Pack_Data
        /// </summary>
        public const UInt16 PUSH_SIGMADATAS = 5;
        #endregion

    }
}
