using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FObjBase;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.OBJ_INTERFACE;
using System.ComponentModel;

namespace FLY.Thick.Base.Server.OBJProxy
{
    public class BoltMapEasy_OBJProxy : FObj
    {
        #region 延时推送 MARKNO
        const int MARKNO_PUSH_PARAMS = 1;
        #endregion

        IBoltMapEasy mBoltMap;

        public BoltMapEasy_OBJProxy(int objsys_idx, IBoltMapEasy boltMap)
            : base(objsys_idx)
        {
            ID = BOLTMAPEASY_OBJ_INTERFACE.ID;
            mBoltMap = boltMap;
            mBoltMap.PropertyChanged += new PropertyChangedEventHandler(mBoltMapService_PropertyChanged);
        }

        void mBoltMapService_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if ((e.PropertyName == "BorderBoltNo_B") ||
                (e.PropertyName == "BorderType") ||
                (e.PropertyName == "Smooth") ||
                (e.PropertyName == "BoltWidth") ||
                (e.PropertyName == "BoltCnt"))
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        byte[] buf;
                        GetValue(null, 0, BOLTMAPEASY_OBJ_INTERFACE.GET_PARAMS, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, BOLTMAPEASY_OBJ_INTERFACE.PUSH_PARAMS,
                            buf);
                    }), this, MARKNO_PUSH_PARAMS);
            }
        }

        public override void GetValue(IFConn from, uint srcid, ushort memid, out byte[] infodata)
        {
            switch (memid)
            {
                case BOLTMAP_OBJ_INTERFACE.GET_PARAMS:
                    {
                        BOLTMAPEASY_OBJ_INTERFACE.Pack_Params p = new BOLTMAPEASY_OBJ_INTERFACE.Pack_Params()
                        {
                            boltwidth = mBoltMap.BoltWidth,
                            boltcnt = mBoltMap.BoltCnt,
                            borderboltno_b = mBoltMap.BorderBoltNo_B,
                            bordertype = mBoltMap.BorderType,
                            smooth = mBoltMap.Smooth
                        };

                        infodata = p.ToBytes();
                    } break;
                default:
                    infodata = null;
                    break;
            }
        }
        public override void SetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case BOLTMAPEASY_OBJ_INTERFACE.SET_PARAMS:
                    {
                        BOLTMAPEASY_OBJ_INTERFACE.Pack_Params p = new BOLTMAPEASY_OBJ_INTERFACE.Pack_Params();
                        if (p.TryParse(infodata))
                        {
                            mBoltMap.BoltWidth = p.boltwidth;
                            mBoltMap.BoltCnt = p.boltcnt;
                            mBoltMap.BorderType = p.bordertype;
                            mBoltMap.BorderBoltNo_B = p.borderboltno_b;
                            mBoltMap.Smooth = p.smooth;
                            mBoltMap.Apply();
                        }
                    } break;
            }
        }

    }
}
