//
//  BLEServiceHandler.h
//  OneCable
//
//  Created by KaRam Kim on 2017. 5. 18..
//  Copyright © 2017년 ntels. All rights reserved.
//

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

typedef enum {
    BLEWlanListType1,
    BLEWlanListType2,
    BLEWlanListType3,
} BLEWlanListType;

static NSString *kBLEChrStWiFiScan = @"SCAN_CHR_UUID";
static NSString *kBLEChrRdWiFiList1 = @"WLAN_LIST1_CHR_UUID";
static NSString *kBLEChrRdWiFiList2 = @"WLAN_LIST2_CHR_UUID";
static NSString *kBLEChrRdWiFiList3 = @"WLAN_LIST3_CHR_UUID";
static NSString *kBLEChrStSSIDArg = @"SSID_ARG_CHR_UUID";
static NSString *kBLEChrStPWDArg = @"PASSWORD_ARG_CHR_UUID";
static NSString *kBLEChrStDHCPArg = @"WF_IP_SET_ARG_CHR_UUID";
static NSString *kBLEChrStSetApply = @"APPLY_CHR_UUID";
static NSString *kBLEChrRdConInfo = @"CONNECTION_CHR_UUID";
static NSString *kBLEChrRdSSID = @"SSID_CHR_UUID";
static NSString *kBLEChrRdBSSID = @"BSSID_CHR_UUID";
static NSString *kBLEChrRnIpSet = @"WF_IP_SET_CHR_UUID";
static NSString *kBLEChrRnIpAddr = @"WF_IP_ADDR_CHR_UUID";



@protocol BLEServiceHandlerDelegate <NSObject>

@optional

- (void) BLEStateChange:(BOOL)state;
- (void) BLEEndScan:(NSMutableArray *)devices;
- (void) BLEConnected:(BTLEDeivceModel *)info;
- (void) BLEDisConnected:(BTLEDeivceModel *)info;
- (void) BLEUpldateDevice:(BTLEDeivceModel *)info;
- (void) BLEWLanUpdateWithKey:(NSString*)kBLEChr result:(NSString*)result;
- (void) BLEWiFiSSIDUpdate:(NSString*)ssid;
- (void) BLEWiFiDHCPUpdate:(id)data;
- (void) BLEWiFiConnectionUpdate:(CBCharacteristic *)info;
- (void) BLEWiFiConnectionInfoUpdateWithKey:(NSString*)kBLEChr result:(NSString*)result;

@end

@interface BLEServiceHandler : NSObject
@property (readonly, nonatomic) BOOL isConnected;
@property (strong, nonatomic) id delegate ;
@property (strong, nonatomic) BTLEDeivceModel *conDevice;


+ (id)sharedManager;


- (void)connect:(BTLEDeivceModel *)info;
- (void)disConnect;
- (BOOL) checkBLEStatus;
- (void) startScan;
- (void) stopScan;

- (NSMutableArray *)getDeviceList;
- (NSString*)getStringValueForCharacteristicWithKey:(NSString*)key;
    
-(CBCharacteristic *)getChrInfo:(NSString *)name;
-(NSString *)getChrName:(CBCharacteristic *)info;
-(NSString *)getStrUUID:(CBCharacteristic *)info;

- (NSString*)hexStringValue:(CBCharacteristic *)input;
- (NSString*)asciiStringValue:(CBCharacteristic *)input;

-(void)sendData:(CBCharacteristic *)chr str:(NSString *)str mustString:(BOOL)mustString;


//WiFi Setting관련 메뉴
// WiFi Ap 스캔
-(void)scanWiFiList;
// WiFi 스캔결과 조회
-(NSString *)getWLanList:(BLEWlanListType)type;
// 스캔된 목록중에 존재하는 SSID를 BLE를 통해 GW에 입력
-(void)setWiFiSSID:(NSString *)ssid;
// 입력된 SSID에 해당하는 AP의 Password를 GW에 입력
-(void)setWiFiPwd:(NSString *)pwd;
// IP 설정타입을 DHCP로 변경
-(void)enableDHCP;

// 설정한 정보를 이용해서 AP에 접속 / IP받아오기
-(void)applyWiFiSettingInfo;
//
-(void)readAndNotifyCharacteristicUUID:(NSString *)uuid
                              isNotify:(BOOL)isNotify;

// connection 후에 정보 확인 ssid bssid ipset ipaddr
-(void)readConnectionWiFiInfo;
//
-(NSString *)getValueFromCharacteristic:(NSString*)type;

@end
