import Foundation

// MARK: - SDK 错误码（双重表示，对齐 PRD §2.3）

/// 错误码数字值（对 PRD 验收）
///
/// ObjC 使用：`MMErrorCodeViewInvalid`、`MMErrorCodeNetworkError` 等
@objc public enum MMErrorCode: Int {
    // 采集错误
    case viewInvalid      = 1001
    case sceneInvalid     = 1002
    case collectFailed    = 1003
    case compressFailed   = 1004
    // 上报错误
    case paramsInvalid    = 2001
    case networkError     = 2002
    case authFailed       = 2003
    case retryExhausted   = 2004
    case uninitialized    = 2005
    case notReady         = 2006
    case strategyDisabled = 2007

    /// 对应的字符串枚举名（用于日志和回调 errorName）
    public var errorName: String {
        switch self {
        case .viewInvalid:      return "VIEW_INVALID"
        case .sceneInvalid:     return "SCENE_INVALID"
        case .collectFailed:    return "COLLECT_FAILED"
        case .compressFailed:   return "COMPRESS_FAILED"
        case .paramsInvalid:    return "PARAMS_INVALID"
        case .networkError:     return "NETWORK_ERROR"
        case .authFailed:       return "AUTH_FAILED"
        case .retryExhausted:   return "RETRY_EXHAUSTED"
        case .uninitialized:    return "UNINITIALIZED"
        case .notReady:         return "NOT_READY"
        case .strategyDisabled: return "STRATEGY_DISABLED"
        }
    }

    /// 默认可读描述
    public var defaultMessage: String {
        switch self {
        case .viewInvalid:      return "View is nil or not attached to window"
        case .sceneInvalid:     return "keyWindow not found or top VC dismissed"
        case .collectFailed:    return "Screenshot capture failed"
        case .compressFailed:   return "Image compression failed"
        case .paramsInvalid:    return "Required fields missing or invalid"
        case .networkError:     return "Network request failed"
        case .authFailed:       return "Server authentication failed (check appId/appKey)"
        case .retryExhausted:   return "Max retry attempts reached"
        case .uninitialized:    return "SDK not initialized, call MaterialMonitor.initialize() first"
        case .notReady:         return "Upload config incomplete (appId/appKey missing)"
        case .strategyDisabled: return "Material monitoring disabled for this placement/network/style"
        }
    }
}
