using System;
using BingoBrain;
using BingoBrain.Core;
using UnityEngine;

public class TomorrowSystem : BaseSystem
{
    public TomorrowSystem(bool isAutoInit = true)
    {
        if (isAutoInit)
        {
            Init();
        }
    }
    public override void Init()
    {
        base.Init();
        AddListener();
    }

    private void AddListener()
    {
        CtrlDispatcher.Instance.AddPriorityListener(CtrlMsg.Game_Start, GameStart);
    }

    private void GameStart(object o)
    {
        Hall.Instance.UpdateSecondEvent += CheckNewDay;
        CheckNewDay();
    }


    private void CheckNewDay()
    {
        if (GameHelper.GetNowTime() > PreferencesMgr.Instance.NextNewDayTime)
        {
            DateTime dateTime = DateTimeBoardk.Instance.GetDateTime(DateTimeBoardk.Instance.GetServerCurrTimestamp());
            dateTime = dateTime.AddDays(1);
            dateTime = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day);
            PreferencesMgr.Instance.NextNewDayTime = (long)DateTimeBoardk.Instance.GetTimestamp(dateTime);
            CtrlDispatcher.Instance.Dispatch(CtrlMsg.GameNewDays);
            Debug.Log("NewDay");
        }

    }
}