#import <Foundation/Foundation.h>
#import <WebKit/WebKit.h>
#import "TQSignCallbacks.h"

NS_ASSUME_NONNULL_BEGIN

/// 决策结果。
typedef NS_ENUM(NSInteger, TQDownloadDecision) {
    /// 已处理,导航应当 `.cancel`
    TQDownloadDecisionCancel = 0,
    /// 不处理,导航应当 `.allow`
    TQDownloadDecisionAllow = 1,
    /// 应当下载:导航应当 `.cancel`,由调用方启动 URLSession 下载
    TQDownloadDecisionDownload = 2,
};

/// 通用下载响应处理器(升级自原 PdfNavigationResponseHandler)。
///
/// **触发点**:`WKNavigationDelegate.decidePolicyFor navigationResponse`
///
/// **识别条件**(任一即视为下载):
/// - response MIME 命中可下载白名单(PDF / Office 文档 / 压缩包等)
/// - HTTP `Content-Disposition: attachment`(case-insensitive,值含 attachment 即触发)
/// - `canShowMIMEType == NO`(WKWebView 无法渲染的类型)
///
/// **策略**(方案 C:统一 URLSession + Cookie 同步,design.md D23):
/// - 全版本统一:返回 `Download`,由 `TQNavigationDelegate` 调用 `TQDownloadManager` 处理。
@interface TQDownloadResponseHandler : NSObject

+ (TQDownloadDecision)decideForResponse:(WKNavigationResponse *)navigationResponse
                                onEvent:(nullable TQOnEventBlock)onEvent;

/// 是否符合「下载」语义(基于 MIME 白名单或 Content-Disposition)
+ (BOOL)isDownloadable:(NSURLResponse *)response;

@end

NS_ASSUME_NONNULL_END
