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

#ifndef AliyunIdentityUtils_h
#define AliyunIdentityUtils_h

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "UIView+Aliyun.h"
#import "NSArray+Aliyun.h"
#import "UIColor+Aliyun.h"
#import "NSDictionary+Aliyun.h"
#import "UIViewController+Aliyun.h"
#import "UIImage+Aliyun.h"
#import "IDVLogger.h"
#import <AVFoundation/AVFoundation.h>

//! Project version number for AliyunIdentityUtils.
FOUNDATION_EXPORT double AliyunIdentityUtilsVersionNumber;

//! Project version string for AliyunIdentityUtils.
FOUNDATION_EXPORT const unsigned char AliyunIdentityUtilsVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <AliyunIdentityUtils/PublicHeader.h>

// P2-Encap-003: 运行时反射跨模块耦合 → 协议注入
// Why — Utils 层通过 NSClassFromString/performSelector 访问 Platform 层的
//   AliyunIdentityCenter.extParams，缺乏类型安全且无法被静态分析工具跟踪
// How — 定义 IDVConfigProvider 协议，Platform 层注册实现，Utils 层通过协议调用
@protocol IDVConfigProvider <NSObject>
- (NSDictionary *)extParams;
@end

@interface AliyunIdentityUtils : NSObject

+ (void)setConfigProvider:(id<IDVConfigProvider>)provider;
+ (id<IDVConfigProvider>)configProvider;

+ (NSString *)appName;

+ (NSString *)appVersion;

+ (NSString *)osVersion;

+ (NSString*)deviceVersion;

+ (BOOL)isNetworkResValid:(NSDictionary *)dic;

+ (NSDictionary *)json2Dictionary:(NSString *)json;

+ (UIImage *)fixTakenPhoto:(UIImage *)aImage;

+ (UIImage *)cropImage:(UIImage *)srcImage withSrcRect:(CGRect) srcRect withDstRect:(CGRect) dstRect;

+ (UIImage *)cropImage:(UIImage *)srcImage cameraResolution:(CGSize)cameraResolution screenResolution:(CGSize)screenResolution cropRect:(CGRect)cropRect;

+ (NSString *)genOssFileName:(NSString *) prefix withType:(NSString *)type whithExt:(NSString *)fileExt;

+ (NSData *)scaleImage:(UIImage *)srcImage withMaxWidth:(CGFloat) maxWidth withQuality:(CGFloat) quality;
+ (UIImage *)scaleImage:(UIImage *)srcImage withMaxWidth:(CGFloat) maxWidth;

+ (long)systemCurrentMiliSeconds;
+ (long)systemCurrentSeconds;

+ (void)initLanguage;
+ (NSString*)getLocalizedString:(NSString*)keyName;

+ (void)generateVideoFileWithFileName:(NSString *)fileName imageArray:(NSArray *)imageArr filePath:(NSURL *)filePath outputSize:(CGSize)outputSize handler:(void (^)(void))handler;

+ (void)removeWorkingDirectoryWithPath:(NSURL *)filePath;

+ (void)createWorkingDirectoryWithPath:(NSURL *)filePath;

+ (CVPixelBufferRef )pixelBufferFromCGImage:(CGImageRef)image size:(CGSize)size;

+ (UIColor *)colorFromHexString:(NSString *)hexString;

+ (UIImage *)imageFromBase64String:(NSString *)base64String;

+ (BOOL )checkDataSourceWithValue:(id)value key:(NSString *)key;

+ (UIFont *)defaultFontWithSize:(CGFloat)size systemFont:(UIFont *)systemFont;

+ (void) lp:(int)key withId:(NSString *)certifyId ;

+ (NSString *)getDateStr;

+ (NSString *)getPemPublicKey;

// Utils-Naming-001: 名为 getRSASign 但实现与 RSA 签名无关，仅生成 16 位随机 nonce
// 作为会话标识使用。保留方法名以避免破坏外部 ABI，调用方请参考实现。
+ (NSString *)getRSASign;
+ (NSString*)getPreferredLanguage;

+ (NSString *)getFaceActionWithCode:(NSString *)code;
+ (NSString *)getFaceActionWithTask:(NSString *)task;

+ (NSMutableArray *)randomItemsFromArray:(NSArray *)array count:(NSInteger)count;

// P2-DupCode-003: convertDateToShortFormat 从 NFC 模块提取到 Utils 层复用
// Why — AliyunIdentityNFC.m 和 IDVNFCGuidePageViewController.m 各有一份完全相同的实现
// How — 统一提取为 AliyunIdentityUtils 类方法，两处改为调用 Utils
/// 将 YYYY-MM-DD 格式日期转换为 YYMMDD 短格式（护照 MRZ 用）
+ (NSString *)convertDateToShortFormat:(NSString *)dateString;

/// 当前 App CPU 使用率，单位：%
+ (double)currentAppCPUUsage;

/// 当前 App 内存使用量，单位：MB
+ (double)currentAppMemoryUsageMB;

@end

#endif
