using System;

namespace XGame.Framework.Time
{
    /// <summary>
    /// 时钟，内置闹钟和定时器
    /// </summary>
    public interface IClock : ITimeUpdate, IDisposable
    {
        /// <summary>
        /// 设置时间戳，用于校准时间
        /// </summary>
        /// <param name="timestamp">时间戳，单位：毫秒</param>
        /// <param name="clockTyp">时钟类型（客户端时间or服务端时间，默认服务端时间）</param>
        void SetTime(long timestamp, ClockType clockTyp = ClockType.Server);
        /// <summary>
        /// 获取当前时间戳（毫秒）
        /// </summary>
        /// <param name="clockTyp">时钟类型（客户端时间or服务端时间，默认服务端时间）</param>
        /// <returns></returns>
        long GetNowTime(ClockType clockTyp = ClockType.Server);

        /// <summary>
        /// 添加闹钟
        /// </summary>
        /// <param name="triggerTimestamp">目标时间戳（毫秒）</param>
        /// <param name="action">回调</param>
        /// <param name="clockTyp">时钟类型（客户端时间or服务端时间，默认服务端时间）</param>
        /// <returns>此闹钟</returns>
        IAlarm AddAlarm(long triggerTimestamp, Action action, ClockType clockTyp = ClockType.Server);

        /// <summary>
        /// 添加计时器
        /// </summary>
        /// <param name="delay">延时（毫秒）</param>
        /// <param name="action">回调</param>
        /// <returns>此计时器</returns>
        ITimer AddDelayTimer(int delay, Action action);

        /// <summary>
        /// 添加循环定时器（使用客户端时间）
        /// </summary>
        /// <param name="interval">循环间隔，单位：毫秒</param>
        /// <param name="action">触发事件，参数为循环的次数</param>
        /// <param name="loopTime">循环次数, 默认-1（-1为无限，0和1都是1次）</param>
        /// <returns>定时器</returns>
        ITimer AddLooperTimer(int delay, int interval, Action<int> action, int loopTime = -1);
    }
}
