//
//   DDMATrackManager.h
//   DDMAMapKit_Private
//   Created by DDIsFriend on 2023/3/5.
    

#import <Foundation/Foundation.h>
#import <AMapFoundationKit/AMapFoundationKit.h>
#import <AMapTrackKit/AMapTrackKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface DDMATrackManager : NSObject
+ (instancetype)shareManager;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;

+ (void)startWithAppKey:(nullable NSString *)appKey;

@property (nonatomic, copy)NSString *serviceID; // 初始化猎鹰服务前必须设置服务id
@property (nonatomic, copy)NSString *fullAccuracyPurpose; // 初始化猎鹰服务前必须设置
@property (nonatomic, copy)NSString *terminalID; // 启动服务前必须设置设备id
@property (nonatomic, copy)NSString *terminalName; // 这应该是一个唯一的名字，利用它来获取terminalID
@property (nonatomic, copy,nullable)NSString *trackID; // 当轨迹id存在时，上报服务回保存在trackID中，否则将以散点形式上报
@property (nonatomic, assign)BOOL isServing; // 是否已开启服务
@property (nonatomic, assign)BOOL isGathering; // 是否已开启采集

// 初始化猎鹰服务
- (void)initTraceService;

/**
 * @brief 设定定位信息的采集周期和上传周期，注意：上传周期必须为采集周期的整数倍
 * @param gatherTimeInterval 定位信息的采集周期，单位秒，有效值范围[1, 60]
 * @param packTimeInterval 定位信息的上传周期，单位秒，有效值范围[5, 3000]
 */
- (void)changeGatherAndPackTimeInterval:(NSInteger)gatherTimeInterval packTimeInterval:(NSInteger)packTimeInterval;

/**
 * @brief 设定允许的本地缓存最大值
 * @param cacheMaxSize 本地缓存最大值，单位MB，默认+∞，有效值范围[50,+∞)。
 * @return 是否设定成功
 */
- (BOOL)setLocalCacheMaxSize:(NSInteger)cacheMaxSize;

//查询终端是否存在
/// @warning 开始上报前先创建terminal，可以拿到terminalID
- (void)queryTerminal:(NSString *)terminalName;

// 创建轨迹
/// @warning 开始上报到指定轨迹前先创建track，可以拿到trackID
- (void)addTrackID;

/// 启动猎鹰服务，不建议直接开启服务，应该使'- (void)queryTerminal:(NSString *)terminalName'方法来开启服务
/// @warning serviceID,terminalID必不可少，而trackID是指定轨迹时才需要
- (void)startService;

// 关闭猎鹰服务
- (void)stopService;

// 开启采集服务
- (void)startGatherAndPack;

// 关闭采集服务
- (void)stopGatherAndPack;

// 创建轨迹成功的回调
@property (nonatomic, copy,nullable)void(^addTrackOnDone)(AMapTrackAddTrackRequest *request,AMapTrackAddTrackResponse *response);

// 开始服务的回调
@property (nonatomic, copy,nullable)void(^startServiceOnDone)(AMapTrackErrorCode error);
// 关闭服务的回调
@property (nonatomic, copy,nullable)void(^stopServiceOnDone)(AMapTrackErrorCode error);

// 开始采集的回调
@property (nonatomic, copy,nullable)void(^startGatherAndPackOnDone)(AMapTrackErrorCode error);
// 关闭采集的回调
@property (nonatomic, copy,nullable)void(^stopGatherAndPackOnDone)(AMapTrackErrorCode error);

// query失败回调
@property (nonatomic, copy,nullable)void(^queryFailWithErrorOnDone)(NSError *error,id request);

// 查询设备位置,queryLastPointOnDone回调
- (void)queryLastPointWith:(nullable NSString *)trackID;
@property (nonatomic, copy,nullable)void(^queryLastPointOnDone)(AMapTrackQueryLastPointRequest *request,AMapTrackQueryLastPointResponse *response);

// 查询设备一段时间内的行驶里程,queryTrackDistanceOnDone回调
- (void)queryTrackDistanceWith:(long long)startTime endTime:(long long)endTime trackID:(nullable NSString *)trackID;
@property (nonatomic, copy,nullable)void(^queryTrackDistanceOnDone)(AMapTrackQueryTrackDistanceRequest *request,AMapTrackQueryTrackDistanceResponse *response);

@end

NS_ASSUME_NONNULL_END
