#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/// SDK 内部事件协议(标记协议)。
///
/// **设计要点**:
/// 用「marker protocol + N 个具体事件类」实现可扩展的事件流,客户用 `isKindOfClass:` 分发:
/// ```objc
/// callbacks.onEvent = ^(id<TQSdkEvent> event) {
///     if ([event isKindOfClass:[TQPageStartedEvent class]]) {
///         TQPageStartedEvent *e = (TQPageStartedEvent *)event;
///         NSLog(@"page started: %@", e.url);
///     }
/// };
/// ```
@protocol TQSdkEvent <NSObject>
@end


// ─────────────────────────────────────────────────────────────────────
// 1. 页面生命周期
// ─────────────────────────────────────────────────────────────────────

/// WebView 开始加载某 URL(主框架)
@interface TQPageStartedEvent : NSObject <TQSdkEvent>
@property (nonatomic, copy, readonly) NSString *url;
- (instancetype)initWithUrl:(NSString *)url;
@end

/// WebView 主框架加载完成
@interface TQPageFinishedEvent : NSObject <TQSdkEvent>
@property (nonatomic, copy, readonly) NSString *url;
- (instancetype)initWithUrl:(NSString *)url;
@end


// ─────────────────────────────────────────────────────────────────────
// 2. 权限
// ─────────────────────────────────────────────────────────────────────

/// Web 端请求的权限已被系统授予
@interface TQPermissionGrantedEvent : NSObject <TQSdkEvent>
@property (nonatomic, copy, readonly) NSArray<NSString *> *permissions;
- (instancetype)initWithPermissions:(NSArray<NSString *> *)permissions;
@end

/// Web 端请求的权限被用户拒绝
@interface TQPermissionDeniedEvent : NSObject <TQSdkEvent>
@property (nonatomic, copy, readonly) NSArray<NSString *> *permissions;
- (instancetype)initWithPermissions:(NSArray<NSString *> *)permissions;
@end


// ─────────────────────────────────────────────────────────────────────
// 3. Scheme 拦截
// ─────────────────────────────────────────────────────────────────────

@interface TQSchemeInterceptedEvent : NSObject <TQSdkEvent>
@property (nonatomic, copy, readonly) NSString *scheme;
@property (nonatomic, copy, readonly) NSString *url;
- (instancetype)initWithScheme:(NSString *)scheme url:(NSString *)url;
@end

@interface TQSchemeNotMatchedEvent : NSObject <TQSdkEvent>
@property (nonatomic, copy, readonly) NSString *url;
- (instancetype)initWithUrl:(NSString *)url;
@end


// ─────────────────────────────────────────────────────────────────────
// 4. 网络与渲染错误
// ─────────────────────────────────────────────────────────────────────

/// `decidePolicyFor navigationAction/navigationResponse` 主框架失败
@interface TQLoadErrorEvent : NSObject <TQSdkEvent>
@property (nonatomic, copy, readonly) NSString *url;
@property (nonatomic, assign, readonly) NSInteger errorCode;
@property (nonatomic, copy, readonly) NSString *errorDescription;
- (instancetype)initWithUrl:(NSString *)url
                  errorCode:(NSInteger)errorCode
                description:(NSString *)description;
@end

/// 主框架 HTTP 错误状态码(>=400)
@interface TQHttpErrorEvent : NSObject <TQSdkEvent>
@property (nonatomic, copy, readonly) NSString *url;
@property (nonatomic, assign, readonly) NSInteger statusCode;
@property (nonatomic, copy, readonly) NSString *reasonPhrase;
- (instancetype)initWithUrl:(NSString *)url
                 statusCode:(NSInteger)statusCode
               reasonPhrase:(NSString *)reasonPhrase;
@end

/// SSL / TLS 错误。SDK 已强制 cancel,业务侧可弹「证书异常」之类提示。
@interface TQSslErrorEvent : NSObject <TQSdkEvent>
@property (nonatomic, copy, readonly) NSString *url;
@property (nonatomic, assign, readonly) NSInteger primaryError;
- (instancetype)initWithUrl:(NSString *)url primaryError:(NSInteger)primaryError;
@end


// ─────────────────────────────────────────────────────────────────────
// 5. 下载
// ─────────────────────────────────────────────────────────────────────

@interface TQDownloadStartEvent : NSObject <TQSdkEvent>
@property (nonatomic, copy, readonly) NSString *url;
@property (nonatomic, copy, readonly) NSString *mimeType;
@property (nonatomic, copy, readonly) NSString *contentDisposition;
- (instancetype)initWithUrl:(NSString *)url
                   mimeType:(NSString *)mimeType
         contentDisposition:(NSString *)contentDisposition;
@end

@interface TQDownloadCompletedEvent : NSObject <TQSdkEvent>
@property (nonatomic, copy, readonly) NSString *url;
@property (nonatomic, copy, readonly) NSString *localPath;
- (instancetype)initWithUrl:(NSString *)url localPath:(NSString *)localPath;
@end

@interface TQDownloadFailedEvent : NSObject <TQSdkEvent>
@property (nonatomic, copy, readonly) NSString *url;
@property (nonatomic, copy, readonly) NSString *reason;
- (instancetype)initWithUrl:(NSString *)url reason:(NSString *)reason;
@end


// ─────────────────────────────────────────────────────────────────────
// 6. 渲染进程崩溃
// ─────────────────────────────────────────────────────────────────────

/// WKWebView Web Content 进程被系统终止(iOS 低内存时触发)。
///
/// **Android 等价**:`RenderProcessGone(didCrash, url)`。
@interface TQWebContentProcessTerminatedEvent : NSObject <TQSdkEvent>
@property (nonatomic, copy, readonly) NSString *url;
- (instancetype)initWithUrl:(NSString *)url;
@end


// ─────────────────────────────────────────────────────────────────────
// 7. UA 注入失败
// ─────────────────────────────────────────────────────────────────────

@interface TQUserAgentInjectFailedEvent : NSObject <TQSdkEvent>
@property (nonatomic, copy, readonly) NSString *reason;
- (instancetype)initWithReason:(NSString *)reason;
@end

NS_ASSUME_NONNULL_END
