//
//  DDTimerManager.h
//  DDToolsKit_Private
//  Created by DDIsFriend on 2022/7/29.

#import <Foundation/Foundation.h>
#import "DDTimerObject.h"

NS_ASSUME_NONNULL_BEGIN

#define TIME_FOREVER (~0ull)

@interface DDTimerManager : NSObject
/**
 *return a static instance.
 */
+ (instancetype)dd_shareManager;

- (instancetype)init NS_UNAVAILABLE;

+ (instancetype)new NS_UNAVAILABLE;

/**
 *add a timerObject to the timerManager.
 *@param timerName a timerName.
 *@param timeInterval The nanosecond interval for the timer.
 *@param repeatCount if repeatCount is 0, the timer will cycle always.
 *@param delayTimeInterval you can set Time_Forever , then manual wake up timer by invoked 'makeTimerActivateNamed' .
 *@param timerBlock what to do in this timer.
 *@param completionBlock this block invoked by adding timer success.
 *@warning completionBlock is invoked async.
 */
- (void)dd_addTimerWithName:(NSString *)timerName timeInterval:(NSTimeInterval)timeInterval repeatCount:(NSUInteger)repeatCount delay:(NSTimeInterval)delayTimeInterval timerBlock:(nullable void(^)(DDTimerManager * _timerManager,DDTimerObject *_Nullable timerObject, NSUInteger timerObjectIndex))timerBlock completionBlock:(nullable void(^)(void))completionBlock;

/**
 * the timerObject is weather activate now.
 *@param timerName a timerName.
 */
- (DDTimerRunState)dd_runStateAboutTimerObjectNamed:(NSString *)timerName;

/**
 *wheather timerObject is contained  in the timerManager.
 *@param timerName a timerObject name.
 */
- (BOOL)dd_containTimerNamed:(NSString *)timerName;

/**
 *manual invoke timer activate.
 *@param timerName a timerObject name.
 */
- (void)dd_makeTimerActivateNamed:(NSString *)timerName;

/**
 *manual invoke timer suspend.
 *@param timerName a timerObject name.
 */
- (void)dd_makeTimerSuspendNamed:(NSString *)timerName;

/**
 *manual invoke timer resume.
 *@param timerName a timerObject name.
 */
- (void)dd_makeTimerResumeNamed:(NSString *)timerName;

/**
 *remove a timerObject from the timerManager.
 *@param timerObject a timerObject.
 */
- (void)dd_removeTimer:(DDTimerObject *)timerObject;

/**
 *remove a timerObject from the timerManager.
 *@param timerName a timerObject name.
 */
- (void)dd_removeTimerNamed:(NSString *)timerName;

/**
 * remove all timers.
 */
- (void)dd_removeAllTimer;
@end

NS_ASSUME_NONNULL_END
