//
//  LoxilyLocalize.h
//  iLocalizeSDK
//
//  Created by AIHelp on 2020/7/10.
//  Copyright © 2020 AIHelp. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "LoxilyLocalizeUserConfig.h"
#import "LoxilyTranslationSuggestion.h"
#import "GGReviewResult.h"

/* callback for download string complete (legacy C function pointer, no error info) */
typedef void (*GGTranslationPreparedCallback)(bool success);

/* callback for download string complete (block form, carries errorMsg on failure) */
typedef void (^LoxilyTranslationPreparedBlock)(BOOL success, NSString * _Nullable errorMsg);

/* callback for screenshot review */
typedef void(^LoxilyReviewCompletion)(NSArray<GGReviewResult *> * _Nullable results, NSString * _Nullable summary, NSError * _Nullable error);

/* callback for headless community suggestion submit. On success error is nil; otherwise ratingCount/suggestionCount are 0. */
typedef void(^LoxilySuggestSubmitCallback)(NSInteger ratingCount, NSInteger suggestionCount, NSError * _Nullable error);

@interface LoxilyLocalize : NSObject

/**
 * Initialize Loxily Localize SDK
 *
 * When initializing Loxily Localize you must pass these three tokens. You initialize Loxily Localize by adding the following lines in the implementation file for your app delegate, ideally at the top of application:didFinishLaunchingWithOptions
 * If you want to use a test string file, refer to the initialization method below
 * @param appKey This is your developer API Key
 * @param isInternationalizing  We did accelerations for different regions.  set true for international, set false for China
 * @param language  This is the init  language
 */
+ (void)initWithAppKey:(NSString *)appKey
              language:(NSString *)language
  isInternationalizing:(BOOL)isInternationalizing;

/**
 * Initialize Loxily Localize SDK
 *
 * When initializing Loxily Localize you must pass these three tokens. You initialize Loxily Localize by adding the following lines in the implementation file for your app delegate, ideally at the top of application:didFinishLaunchingWithOptions
 * @param appKey This is your developer API Key
 * @param language  This is the init  language
 * @param isInternationalizing  We did accelerations for different regions.  set true for international, set false for China
 * @param isDebug  It may be useful to you during debugging. The default is false. If true, it will download the debug string file
 */
+ (void)initWithAppKey:(NSString *)appKey
              language:(NSString *)language
  isInternationalizing:(BOOL)isInternationalizing
               isDebug:(BOOL)isDebug;

/**
 * Gets the corresponding string based on the code
 *
 * The code needs to correspond to the Loxily Localize website one to one
 * @param code string code, it is required
 * @return The string you want, If no string is found, an empty string is returned
 */
+ (NSString *)getStringWithCode:(NSString *)code;

/**
 * Gets the corresponding string string based on the code
 *
 * The code needs to correspond to the Loxily Localize website one to one
 * @param code string code, it is required
 * @param defaultString The default string
 * @return The string you want, If no string is found, defaultString will be returned
 */
+ (NSString *)getStringWithCode:(NSString *)code defaultString:(NSString *)defaultString;

/**
 * Gets the corresponding string based on the code, tagged with a pageId
 *
 * Convenience overload that also updates the global screenshotPageId, so any
 * subsequent `reviewCurrentScreenWithViewController:` call automatically reports
 * that this code was last seen on `pageId`. Equivalent to calling
 * `+ setScreenshotPageId:` followed by `+ getStringWithCode:`.
 *
 * @param code string code (required)
 * @param pageId page identifier the code is being rendered on (may be nil)
 * @return The string you want, or @"" if not found
 */
+ (NSString *)getStringWithCode:(NSString *)code pageId:(nullable NSString *)pageId;

/**
 * Same as above, with a defaultString fallback.
 */
+ (NSString *)getStringWithCode:(NSString *)code
                         pageId:(nullable NSString *)pageId
                  defaultString:(NSString *)defaultString;

/**
 * Change the string language
 *
 * The call will fail in the following cases :
 * 1. If a Loxily Localize session is already active at the time of invocation
 * 2. Language code is incorrect
 * 3. Corresponding localization file is not found
 * @param lan the string representing the language code. For example, use 'fr' for French.
 */
+ (void)updateLanguage:(NSString *)lan;

/**
 * Register callback for download string complete (legacy form)
 *
 * It will tell you whether the download succeeded or failed.
 * NOTE: This C function pointer form does not carry error details on failure.
 * Prefer the block form `setTranslationPreparedBlock:` which includes `errorMsg`.
 *
 * @param callBack callBack for download string complete
 */
+ (void)setTranslationPreparedCallback:(GGTranslationPreparedCallback)callBack
    __deprecated_msg("Use setTranslationPreparedBlock: instead — the block form carries an errorMsg parameter for failure diagnostics.");

/**
 * Register callback for download string complete (block form)
 *
 * Callback is fired on the main thread when SDK initialization completes.
 * On failure, `errorMsg` contains a short description (e.g. HTTP error reason / API error message).
 * On success, `errorMsg` is nil.
 *
 * @param block invoked once after init completes
 */
+ (void)setTranslationPreparedBlock:(LoxilyTranslationPreparedBlock)block;

/**
 * Whether to print logs.
 *
 * It only works in Debug mode
 * @param enable YES/NO
 */
+ (void)setLogEnable:(BOOL)enable;
 
+ (void)evaluateStringWithCode:(NSString *)code stringContent:(NSString *)stringContent
    __deprecated_msg("Use suggestTranslationWithViewController:stringIds: instead. Internally forwards to suggestTranslation; stringContent is ignored.");

+ (void)setUserConfig:(LoxilyLocalizeUserConfig *)config;

+ (void)evaluateAllStrings
    __deprecated_msg("No-op in current SDK — the per-language batch evaluation flow is removed. Use reviewCurrentScreenWithViewController: for AI-driven review or suggestTranslationWithViewController:stringIds: for community suggestions.");

+ (void)checkStringOverflow:(LoxilyLocalizeCheckOverflowConfig *)config;

/**
 * 设置截图审查上送给后端的页面标识
 *
 * 设置后所有后续 reviewCurrentScreen 系列调用都会带上该 pageId（除非该次调用显式覆盖）。
 * 集成方可在进入不同业务场景时调用本方法，让后台能区分截图来源。
 *
 * @param pageId 页面标识；传 nil 清除
 */
+ (void)setScreenshotPageId:(nullable NSString *)pageId;

+ (void)enableEvaluateFunction:(BOOL)enable
    __deprecated_msg("No-op in current SDK — the legacy local SQLite evaluation toggle is removed. Community suggestions are now handled by submitTranslationSuggestion(s):imageData:callback: without any local-toggle prerequisite.");

/**
 * 截图翻译审查（带回调）
 * 截取当前页面截图，通过 AI 多模态分析文本，匹配平台 string_id 并返回翻译修改建议
 *
 * @param viewController 当前视图控制器
 * @param callback 审查结果回调
 */
+ (void)reviewCurrentScreenWithViewController:(UIViewController *)viewController
                                     callback:(LoxilyReviewCompletion)callback;

/**
 * 截图翻译审查（内置 UI）
 * 截取当前页面截图，通过 AI 分析后在内置浮层中展示审查结果
 *
 * @param viewController 当前视图控制器
 */
+ (void)reviewCurrentScreenWithViewController:(UIViewController *)viewController;

/**
 * 截图翻译审查（内置 UI，string_id 精确匹配）
 * 自动截图，并把指定的 string_id 列表对应的当前译文作为上下文一并提交给 AI，让分析聚焦在这些词条上。
 *
 * @param viewController 当前视图控制器
 * @param stringIds 要审查的 string_id 数组；为空或 nil 时退化为无参版本
 */
+ (void)reviewCurrentScreenWithViewController:(UIViewController *)viewController
                                    stringIds:(nullable NSArray<NSString *> *)stringIds;

/**
 * 截图翻译审查（内置 UI，string_id 精确匹配 + 外部截图）
 * 适用于游戏引擎（Unity / Cocos 等）自取截图的场景。SDK 不会再自动截屏。
 *
 * @param viewController 当前视图控制器
 * @param stringIds 要审查的 string_id 数组；为空或 nil 时不附带 string 上下文
 * @param imageData 截图数据（PNG/JPEG），传 nil 则 SDK 自动截取当前屏幕
 */
+ (void)reviewCurrentScreenWithViewController:(UIViewController *)viewController
                                    stringIds:(nullable NSArray<NSString *> *)stringIds
                                    imageData:(nullable NSData *)imageData;

/**
 * 共创翻译：玩家建议翻译
 * 打开 Agent 页面，展示指定 string_id 对应的当前翻译，玩家选择并输入翻译建议后提交。
 * 前提条件：SDK 已初始化、已通过 setUserConfig: 设置 userId。
 *
 * @param viewController 当前视图控制器
 * @param stringIds 要建议翻译的 string_id 数组（必填）
 */
+ (void)suggestTranslationWithViewController:(UIViewController *)viewController
                                   stringIds:(NSArray<NSString *> *)stringIds;

/**
 * 共创翻译：玩家建议翻译（支持外部传入截图）
 * 适用于游戏引擎自行截图的场景。截图将随建议一起提交，用于 AI 评分参考。
 *
 * @param viewController 当前视图控制器
 * @param stringIds 要建议翻译的 string_id 数组（必填）
 * @param imageData 截图数据（PNG/JPEG），传 nil 则 SDK 自动截取当前屏幕
 */
+ (void)suggestTranslationWithViewController:(UIViewController *)viewController
                                   stringIds:(NSArray<NSString *> *)stringIds
                                   imageData:(nullable NSData *)imageData;

/**
 * 共创翻译：无 UI 提交翻译建议（多条）
 * 集成方使用自己的 UI 收集玩家评分/翻译建议，再通过该方法批量提交，SDK 不弹任何页面。
 * SDK 内部按 stringId 自动回填 currentTranslation。
 * 前提条件：SDK 已初始化、已通过 setUserConfig: 设置 userId。
 *
 * @param suggestions 翻译建议数组，每条至少包含 stringId，且 rating(>0) 与 suggestedTranslation 至少有一个
 * @param imageData 可选的截图数据（PNG/JPEG），随建议一起提交用于 AI 评分参考；传 nil 不附带截图
 * @param callback 提交回调（主线程）：成功时 error=nil，ratingCount/suggestionCount 来自后端；失败时 error 非空
 */
+ (void)submitTranslationSuggestions:(NSArray<LoxilyTranslationSuggestion *> *)suggestions
                           imageData:(nullable NSData *)imageData
                            callback:(nullable LoxilySuggestSubmitCallback)callback;

/**
 * 共创翻译：无 UI 提交翻译建议（单条便捷重载）
 *
 * @param suggestion 翻译建议
 * @param imageData 可选的截图数据
 * @param callback 提交回调
 */
+ (void)submitTranslationSuggestion:(LoxilyTranslationSuggestion *)suggestion
                          imageData:(nullable NSData *)imageData
                           callback:(nullable LoxilySuggestSubmitCallback)callback;

/**
 * 显示 Agent 浮动气泡按钮（右下角）
 * 点击可自动截图并打开 LoxiBot 对话审查当前页面翻译。
 * 需要集成方主动调用此方法来显示气泡按钮。
 */
+ (void)showAgentBubble;

/**
 * 隐藏 Agent 浮动气泡按钮
 */
+ (void)hideAgentBubble;

@end

