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 COATINGSEGMENT_OBJ_INTERFACE
    {
        #region Pack
        public class Pack_Params : IPack
        {
            public bool enable;
            public bool enSave;
            public int saveCnt;
            public int recentCnt;
            public int inIdxOfVSide;
            public double warningtol_total;
            public double warningtol_distance;
            #region IPack 成员

            public byte[] ToBytes()
            {
                List<byte> buf = new List<byte>();
                buf.AddRange(BitConverter.GetBytes(enable));
                buf.AddRange(BitConverter.GetBytes(enSave));
                buf.AddRange(BitConverter.GetBytes(saveCnt));
                buf.AddRange(BitConverter.GetBytes(recentCnt));
                buf.AddRange(BitConverter.GetBytes(inIdxOfVSide));
                buf.AddRange(BitConverter.GetBytes(warningtol_total));
                buf.AddRange(BitConverter.GetBytes(warningtol_distance));
                return buf.ToArray();
            }

            public bool TryParse(byte[] value)
            {
                if (value.Length < (1 * 2 + 4 * 3 + 8 * 2))
                    return false;
                int idx = 0;
                enable = BitConverter.ToBoolean(value, idx);
                idx++;

                enSave = BitConverter.ToBoolean(value, idx);
                idx++;

                saveCnt = BitConverter.ToInt32(value, idx);
                idx += 4;

                recentCnt = BitConverter.ToInt32(value, idx);
                idx += 4;

                inIdxOfVSide = BitConverter.ToInt32(value, idx);
                idx += 4;


                warningtol_total = BitConverter.ToDouble(value, idx);
                idx += 8;

                warningtol_distance = BitConverter.ToDouble(value, idx);
                idx += 8;
                return true;
            }

            #endregion
        }
        public class Pack_Recent : IPack
        {
            public FlyData_CoatingSegmentHistory[] data;
            public byte[] ToBytes()
            {
                List<byte> buf = new List<byte>();
                buf.AddRange(BitConverter.GetBytes(data.Count()));
                for (int i = 0; i < data.Count(); i++)
                {
                    buf.AddRange(data[i].ToBytes());
                }
                return buf.ToArray();
            }

            public bool TryParse(byte[] value)
            {

                int cnt = 4;
                if (value.Length < cnt)
                    return false;


                int idx = 0;
                int length = BitConverter.ToInt32(value, idx);
                idx += 4;
                data = new FlyData_CoatingSegmentHistory[length];
                for (int i = 0; i < length; i++)
                {
                    data[i] = new FlyData_CoatingSegmentHistory();
                    int count;
                    if (!data[i].TryParse(value, idx, out count))
                        return false;

                    idx += count;
                    cnt += count;
                }
                return true;
            }
        }
        
        #endregion

        #region GetValue
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 GET_PARAMS = 0;
        /// <summary>
        /// CoatingSegmentProfile
        /// </summary>
        public const UInt16 GET_PROFILE = 1;
        /// <summary>
        /// FlyData_CoatingSegmentHistory
        /// </summary>
        public const UInt16 GET_LAST = 2;
        #endregion
        #region SetValue
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 SET_PARAMS = 0;
        /// <summary>
        /// CoatingSegmentProfile
        /// </summary>
        public const UInt16 SET_PROFILE = 1;
        #endregion
        #region PushMsg
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 PUSH_PARAMS = 0;
        /// <summary>
        /// CoatingSegmentProfile       
        /// </summary>
        public const UInt16 PUSH_PROFILE = 1;
        /// <summary>
        /// FlyData_CoatingSegmentHistory
        /// </summary>
        public const UInt16 PUSH_LAST = 2;
        #endregion
        #region CallFunction
        /// <summary>
        /// request:null
        /// reponse:Pack_Recent
        /// </summary>
        public const UInt16 CALL_GETRECENT = 1;
        #endregion
    }
}
