
import LoginBehavior from "../Logic/LoginBehavior";
import EnterRoomBehavior from '../Logic/EnterRoomBehavior';
import BootBheavior from '../Logic/BootBehavior';
import ChatBehavior from '../Logic/ChatBehavior';
import ShareBehavior from '../Logic/ShareBehavior';
import BattleBehavior from '../logic/BattleBehavior';

let LogicUnitManager = (
    function()
    {
        var _behaviorMap = {};
        var _behaviorConsturctFun = {};

        var registerBehaviorContruct = function(behaviorName,constructFun)
        {
            _behaviorConsturctFun[behaviorName] = constructFun;
        };

        registerBehaviorContruct('LoginBehavior', LoginBehavior);
        registerBehaviorContruct('EnterRoomBehavior', EnterRoomBehavior);
        registerBehaviorContruct('BootBehavior', BootBheavior);
        registerBehaviorContruct('ChatBehavior', ChatBehavior);
        registerBehaviorContruct('ShareBehavior', ShareBehavior);
        // registerBehaviorContruct('BattleBehavior', BattleBehavior)

        return {
           getBehavior(behaviorName)
           { 
               if(_behaviorMap[behaviorName])
               {
                   return _behaviorMap[behaviorName];
               }
               else
               {
                   if(_behaviorConsturctFun[behaviorName])
                   {
                    _behaviorMap[behaviorName] =  new _behaviorConsturctFun[behaviorName];
                       return  _behaviorMap[behaviorName];
                   }
                   else
                   {
                      
                   }
               }
           },
       
           destroyBehavior(behaviorName)
           {
             if(_behaviorMap[behaviorName])
             {
                _behaviorMap[behaviorName].destroy();
                delete _behaviorMap[behaviorName];
             }
           }

        };
    }
)();

export default  LogicUnitManager;
