//
//  RYSessionManager.h
//  RYCommonPrinter
//
//  Created by ldc on 2023/12/13.
//

#import <Foundation/Foundation.h>
#import <RYCommunication/RYResolver.h>

@class RYSessionTask;
@class RYSessionManagerHandler;

NS_ASSUME_NONNULL_BEGIN

extern NSErrorDomain RYSessionManagerErrorDomain;

typedef NS_ENUM(NSUInteger, RYSessionManagerError) {
    RYSessionManagerErrorTimeout = 0,
    RYSessionManagerErrorNotConnect,
    RYSessionManagerErrorAccessoryNotFound,
};

@interface RYSessionManagerRequest : NSObject <RYSessionIdentity>

@property (nonatomic, strong) NSData *cmd;

@property (nonatomic, strong) RYSessionManagerHandler *handler;

@property (nonatomic, weak) NSTimer *timer;

@end

@interface RYSessionManagerResponse : NSObject

@property (nonatomic, strong) RYSessionManagerRequest *request;

@property (nonatomic, strong) RYCommonResolveModel *model;

@end

@interface RYSessionManagerHandler : NSObject

@property (nonatomic, copy) void (^success)(RYSessionManagerResponse *);

@property (nonatomic, copy) void (^fail)(NSError *);

@end

@interface RYSessionManager : NSObject

- (instancetype)initWith:(id<RYAccessory>)accessory;

- (instancetype)initWithWriteBlock:(void (^)(NSData *, void(^_Nullable)(NSProgress *)))block;

- (void)request:(RYSessionTask *)task
        success:(void (^)(RYSessionManagerResponse *))successHandler
           fail:(void (^)(NSError *))failHandler
        timeout:(NSUInteger)timeout;

- (void)request:(RYSessionTask *)task
        success:(void (^)(RYSessionManagerResponse *))successHandler
  writeProgress:(void(^ _Nullable)(NSProgress *))progressBlock
           fail:(void (^)(NSError *))failHandler
        timeout:(NSUInteger)timeout;

- (void)receiveModel:(id)object;

@end

NS_ASSUME_NONNULL_END
