#import <Foundation/Foundation.h>

typedef NS_ENUM(NSInteger, DeviceConfigState) {
    DeviceConfigStateIdle = 0,
    DeviceConfigStateConnecting,
    DeviceConfigStateLoggingIn,
    DeviceConfigStateReadingParams,
    DeviceConfigStateWritingParams,
    DeviceConfigStateDone
};

@protocol DeviceConfigEventHandler;

@interface DeviceConfig : NSObject

@property (nonatomic, assign, readonly) DeviceConfigState configState;
@property (nonatomic, retain, readonly) NSMutableArray<NSNumber*>* workingParamsFromDevice;

- (instancetype)initWithDeviceMac:(NSString*)deviceMac
                    devicePassword:(NSString*)devicePassword
                         paramLen:(int)paramLen
                     eventHandler:(id<DeviceConfigEventHandler>)handler;

- (void)start;
- (void)stop;
- (void)saveParamsToDevice:(NSData*)params;

@end

@protocol DeviceConfigEventHandler <NSObject>

- (void)onConnectStatusChanged:(NSString*)mac status:(NSString*)status isConnected:(BOOL)isConnected;
- (void)onParamsRead:(NSString*)mac params:(NSMutableArray<NSNumber*>*)params;
- (void)onParamsSaved:(NSString*)mac success:(BOOL)success errorMsg:(NSString*)errorMsg;
- (void)onFirmwareVersionReceived:(NSString*)mac fwpId:(int)fwpId;

@optional
- (void)onLoginFailed:(NSString*)mac;
- (void)onFirmwareVersionQueryFailed:(NSString*)mac;
- (void)onDeviceFound:(NSString*)mac;
- (void)onParamsQueryStarted:(NSString*)mac;
- (void)onLoginStarted:(NSString*)mac;

@end
