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

namespace FLY.Thick.Base.OBJ_INTERFACE
{
    public class BOLTMAP_OBJ_INTERFACE
    {
        public const UInt32 ID = OBJ_INTERFACE_ID.BOLTMAP_ID;
        #region Pack
        public class Pack_Params : IPack
        {
            public int boltNo1st;
            public Range[] bolts;

            #region IPack 成员

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

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

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

                if (value.Length < (idx + len * 8))
                    return false;

                bolts = new Range[len];
                for (int i = 0; i < len; i++)
                {
                    bolts[i] = new Range();
                    bolts[i].TryParse(value, idx);
                    idx += 8;
                }
                return true;
            }

            #endregion
        }
        public class Pack_BorderParams:IPack
        {
            public BORDER_TYPE bordertype;
            public int borderboltno_b;
            public int borderboltno_e;
            public int smooth;
            #region IPack 成员

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

                buf.AddRange(BitConverter.GetBytes((int)bordertype));
                buf.AddRange(BitConverter.GetBytes(borderboltno_b));
                buf.AddRange(BitConverter.GetBytes(borderboltno_e));
                buf.AddRange(BitConverter.GetBytes(smooth));
                return buf.ToArray();
            }

            public bool TryParse(byte[] value)
            {
                if (value.Length < 16)
                    return false;
                int idx = 0;
                bordertype = (BORDER_TYPE)BitConverter.ToInt32(value, idx);
                idx += 4;
                borderboltno_b = BitConverter.ToInt32(value, idx);
                idx += 4;
                borderboltno_e = BitConverter.ToInt32(value, idx);
                idx += 4;
                smooth = BitConverter.ToInt32(value, idx);
                idx += 4;
                return true;
            }

            #endregion
        }
        public class Pack_BoltsInfo : IPack 
        {
            public int LastBoltNo;
            public int BoltInterval;
            public int BoltWidth;
            public int PosBegin;
            public int PosEnd;

            #region IPack 成员

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

                buf.AddRange(BitConverter.GetBytes(LastBoltNo));
                buf.AddRange(BitConverter.GetBytes(BoltInterval));
                buf.AddRange(BitConverter.GetBytes(BoltWidth));
                buf.AddRange(BitConverter.GetBytes(PosBegin));
                buf.AddRange(BitConverter.GetBytes(PosEnd));
                return buf.ToArray();
            }

            public bool TryParse(byte[] value)
            {
                if (value.Length < 20)
                    return false;
                int idx = 0;
                LastBoltNo = BitConverter.ToInt32(value, idx);
                idx += 4;
                BoltInterval = BitConverter.ToInt32(value, idx);
                idx += 4;
                BoltWidth = BitConverter.ToInt32(value, idx);
                idx += 4;
                PosBegin = BitConverter.ToInt32(value, idx);
                idx += 4;
                PosEnd = BitConverter.ToInt32(value, idx);
                idx += 4;
                return true;
            }

            #endregion
        }
        #endregion

        #region GetValue
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 GET_PARAMS = 0;

        /// <summary>
        /// Pack_BorderParams
        /// </summary>
        public const UInt16 GET_BORDERPARAMS = 1;

        /// <summary>
        /// Pack_BoltsInfo
        /// </summary>
        public const UInt16 GET_BOLTSINFO = 2;

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


        #endregion
        #region PushMsg
        /// <summary>
        /// Pack_Params
        /// </summary>
        public const UInt16 PUSH_PARAMS = 0;
        /// <summary>
        /// Pack_BorderParams
        /// </summary>
        public const UInt16 PUSH_BORDERPARAMS = 1;

        /// <summary>
        /// Pack_BoltsInfo
        /// </summary>
        public const UInt16 PUSH_BOLTSINFO = 2;


        #endregion
    }
}