namespace RedHotRoast
{
    public class RewardUICtrl : BaseUICtrl
    {
        private RewardUI ui;
        private RewardModel model;

        private uint openUIMsg = UICtrlMsg.RewardUI_Open;
        private uint closeUIMsg = UICtrlMsg.RewardUI_Close;

        public RewardData rewardInfo;

        protected override void OnInit()
        {
        }

        protected override void OnDispose()
        {
        }

        public override void OpenUI(object args = null)
        {
            if (ui == null)
            {

                if (args != null)
                {
                    rewardInfo = (RewardData)args;
                }


                ui = new RewardUI(this);
                ui.Open(args);
            }
        }

        public override void CloseUI(object args = null)
        {
            if (ui is { isClose: false })
            {
                ui.Close();
            }

            ui = null;
        }

        public override uint GetOpenUIMsg(string uiName)
        {
            return openUIMsg;
        }

        public override uint GetCloseUIMsg(string uiName)
        {
            return closeUIMsg;
        }

        public void GetReward(int rate = 1)
        {
            foreach (var rewardSingleData in rewardInfo.GetRewardDataList())
            {
                rewardSingleData.rate = rate;
            }

            RewardSystem.GetReward(rewardInfo);
        }

        protected override void AddListener()
        {
            uiCtrlDispatcher.AddListener(openUIMsg, OpenUI);
            uiCtrlDispatcher.AddListener(closeUIMsg, CloseUI);
        }

        protected override void RemoveListener()
        {
            uiCtrlDispatcher.RemoveListener(openUIMsg, OpenUI);
            uiCtrlDispatcher.RemoveListener(closeUIMsg, CloseUI);
        }
    }
}