//
//  AliyunIdentityCenter.h
//  AliyunIdentityPlatform
//
//  Created by nansong.zxc on 2020/7/24.
//  Copyright © 2020 aliyun.com. All rights reserved.
//

#ifndef AliyunIdentityCenter_h
#define AliyunIdentityCenter_h

#import "AliyunIdentityCom.h"
#import <UIKit/UIKit.h>
#import "AliyunIdentityOcrInfo.h"
#import "CustomConfigModel.h"
#import <AliyunIdentityUtils/IDVLogger.h>
extern id g_sharedInstance;

typedef NS_ENUM(NSInteger, AliyunIdentityOSSFileIdx){
    IOF_INVALID,
    IOF_IDCARD_FRONT,
    IOF_IDCARD_BACK,
    IOF_BANK,
    IOF_FACE_IMAGE
};

typedef void(^IDVModuleLaunchBlock)(UIViewController *controller);

@class AliyunIdentityAdapter;

@interface AliyunIdentityCenter : NSObject <IDVMonitorContextProvider>

#pragma mark - Session State

@property(nonatomic, copy) NSString *certifyId;
@property(nonatomic, copy) NSString *protocol;
@property(nonatomic, strong) AliyunIdentityVerifyBlock completionCallback;
@property(nonatomic, strong) NSDictionary *extParams;
@property(nonatomic, strong) UIViewController *currentViewController;
@property(nonatomic, strong) NSDictionary *deviceConfig;
@property(nonatomic, copy) NSString *metaInfo;
@property(nonatomic, strong) NSTimer *sdkMaxTimeOutTimer;
@property(atomic, assign) BOOL isBusy;
@property(nonatomic, assign) long verifyStartTime;
@property(nonatomic, strong) CustomConfigModel *customConfig;
@property(nonatomic, strong) NSString *sign;
@property(nonatomic, strong) NSString *timestamp;

#pragma mark - Task & Template Config

@property(atomic, strong) NSDictionary *toygerUploadParams;
@property(atomic, strong) NSDictionary *toygerAlgorithmParams;
@property(atomic, strong) NSMutableArray *taskArray;
@property(nonatomic, copy) NSMutableArray *TemplateConfig;
@property(nonatomic, assign) long TemplateRanCount;
@property(nonatomic, copy) NSString *TemplateType;
@property(nonatomic, strong) NSString *model;

#pragma mark - Network Config

@property(nonatomic, strong) NSMutableArray *authUrls;
@property(nonatomic, strong) NSString *useProtocol;
@property(nonatomic, strong) NSString *websocketSwitch;
@property(nonatomic, strong) NSString *logLevel;
@property(nonatomic, strong) NSString *useOssSdk;
@property(nonatomic, strong) NSString *fileType;

#pragma mark - Encryption

@property(nonatomic, strong) NSData *aesIV;

#pragma mark - OCR State

@property(nonatomic, strong) AliyunIdentityOcrInfo *ocrInfo;
@property(nonatomic, strong) UIImage *idcardFrontImage;
@property(nonatomic, strong) UIImage *idcardFrontCropImage;
@property(nonatomic, strong) UIImage *idcardFrontCropBackImage;
@property(nonatomic, copy) NSString *idcardFrontOss;
@property(nonatomic, strong) NSString *idcardFrontImageBase64;
@property(nonatomic, strong) UIImage *idcardBackImage;
@property(nonatomic, strong) UIImage *idcardBackCropImage;
@property(nonatomic, copy) NSString *idcardBackOss;
@property(nonatomic, strong) NSString *idcardBackImageBase64;
@property(nonatomic, assign) BOOL isSelectedPhoto;
@property(nonatomic, strong) NSArray *docPageConfig;
@property(nonatomic, assign) int docPageNumber;
@property(nonatomic, strong) NSString *showGuidePage;
@property(nonatomic, strong) NSString *docModel;
@property(nonatomic, strong) NSString *ocrValueStandard;
@property(nonatomic, strong) NSString *cardAllowSizeRatio;
@property(nonatomic, strong) NSString *cardAllowTiltAngle;

#pragma mark - Face Liveness State

@property(nonatomic, strong) UIImage *faceHighQualityImage;
@property(nonatomic, strong) NSData *faceHighQualityImageHash;
@property(nonatomic, strong) NSString *faceImageOss;
@property(nonatomic, strong) NSString *faceImageBase64;
@property(nonatomic, strong) UIImage *faceOpenMouthImage;
@property(nonatomic, strong) NSData *faceOpenMouthImageHash;
@property(nonatomic, strong) NSString *openMouthImageOss;
@property(nonatomic, strong) NSString *openMouthImageBase64;
@property(nonatomic, strong) UIImage *faceBlinkImage;
@property(nonatomic, strong) NSData *faceBlinkImageHash;
@property(nonatomic, strong) NSString *faceBlinkImageOss;
@property(nonatomic, strong) NSString *faceBlinkImageBase64;
@property(nonatomic, strong) UIImage *faceHeadLeftImage;
@property(nonatomic, strong) NSData *faceHeadLeftImageHash;
@property(nonatomic, strong) NSString *faceHeadLeftImageOss;
@property(nonatomic, strong) NSString *faceHeadLeftImageBase64;
@property(nonatomic, strong) UIImage *faceHeadRightImage;
@property(nonatomic, strong) NSData *faceHeadRightImageHash;
@property(nonatomic, strong) NSString *faceHeadRightImageOss;
@property(nonatomic, strong) NSString *faceHeadRightImageBase64;
@property(nonatomic, assign) BOOL isOpenFaceBackup;
@property(nonatomic, strong) UIImage *backupFaceImage;
@property(nonatomic, strong) NSData *backupFaceImageHash;
@property(nonatomic, strong) NSString *backupFaceImageOss;
@property(nonatomic, strong) NSString *backupFaceImageBase64;
@property(nonatomic, strong) NSString *faceLivenessFarNearOpen;
@property(nonatomic, strong) NSDictionary *faceLivenessFarNearConfig;
@property(nonatomic, strong) NSString *appQualityCheck;
@property(nonatomic, strong) NSString *clientLivenessTimeout;
@property(nonatomic, strong) UIImage *farImage;
@property(nonatomic, strong) NSData *farImageHash;
@property(nonatomic, strong) NSString *farImageOss;
@property(nonatomic, strong) NSString *farBase64;
@property(nonatomic, strong) UIImage *closeImage;
@property(nonatomic, strong) NSData *closeImageHash;
@property(nonatomic, strong) NSString *closeImageOss;
@property(nonatomic, strong) NSString *closeImageBase64;
@property(nonatomic, strong) NSString *deviceAlgoDegrade;
@property(nonatomic, strong) NSString *docVideo;

#pragma mark - Video State

@property(nonatomic, strong) NSData *zimVideoHash;
@property(nonatomic, strong) NSString *zimVideoOss;
@property(nonatomic, strong) NSData *photinusVideoHash;
@property(nonatomic, strong) NSString *photinusVideoOss;

#pragma mark - NFC Config

@property(nonatomic, strong) NSDictionary *nfcConfig;
@property(nonatomic, assign) int nfcMode;

#pragma mark - Localization & Agreement

@property(nonatomic, strong) NSString *authorizationAgreementLinkEn;
@property(nonatomic, strong) NSString *authorizationAgreementLinkId;

#pragma mark - Adapter

/// 当前活跃的 Adapter 实例 (通过 installWithAdapter: 注入)
@property(nonatomic, strong) AliyunIdentityAdapter *adapter;

#pragma mark - Public Methods

+ (AliyunIdentityCenter *) sharedInstance;
- (void)sendResWithCode:(int)code withMessage:(NSString *)message withSubCode:(NSString *)subCode withOcrInfo:(AliyunIdentityOcrInfo *)ocrInfo;
- (void)clear;

#pragma mark - Module Router

// P2-Encap-004: 跨模块 NSClassFromString → 模块注册/分发
// Why — OCR/NFC/Face 平级框架通过 NSClassFromString + performSelector 互相调用，
//   缺乏编译期类型检查且无法被静态分析工具追踪
// How — Platform 层提供模块注册表，各模块在 +load 时注册启动 block，
//   调用方通过类型安全的 launchModule:withController: 替代反射调用

+ (void)registerLauncher:(IDVModuleLaunchBlock)launcher forModule:(NSString *)moduleName;
+ (BOOL)launchModule:(NSString *)moduleName withController:(UIViewController *)controller;

@end
#endif /* AliyunIdentityCenter_h */
