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

namespace FLY.Thick.Base.Server.OBJProxy
{
    public class Password_OBJProxy : FObj
    {
        #region 延时推送 MARKNO

        #endregion

        IPasswordService mPassword;

        public Password_OBJProxy(int objsys_idx, IPasswordService password)
            : base(objsys_idx)
        {
            ID = PASSWORD_OBJ_INTERFACE.ID;
            mPassword = password;
            mPassword.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mPassword_PropertyChanged);
        }
        public Password_OBJProxy(int objsys_idx, IPasswordService password, UInt32 id)
            : base(objsys_idx)
        {
            ID = id;
            mPassword = password;
            mPassword.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mPassword_PropertyChanged);
        }

        void mPassword_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "PWs") 
            {

                    byte[] buf;
                    GetValue(null, 0, PASSWORD_OBJ_INTERFACE.GET_PWLIST, out buf);
                    CurrObjSys.PushObjInfoEx(
                        this, PASSWORD_OBJ_INTERFACE.PUSH_PWLIST,
                        buf);
            }
        }

        #region FObj 重载
        public override void GetValue(IFConn from, uint srcid, ushort memid, out byte[] infodata)
        {
            switch (memid)
            {
                case PASSWORD_OBJ_INTERFACE.GET_PWLIST:
                    {
                        PASSWORD_OBJ_INTERFACE.Pack_List p = new PASSWORD_OBJ_INTERFACE.Pack_List()
                        {
                            list = mPassword.PWs
                        };
                        infodata = p.ToBytes();
                    } break;
                default:
                    infodata = null;
                    break;
            }
        }
        public override void SetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case PASSWORD_OBJ_INTERFACE.SET_PWLIST:
                    {
                        PASSWORD_OBJ_INTERFACE.Pack_List p = new PASSWORD_OBJ_INTERFACE.Pack_List();
                        p.list = mPassword.PWs;
                        if (!p.TryParse(infodata))
                            break;
                        mPassword.Apply();
                    } break;
            }
        }

        #endregion

    }
}
