//
//  S1Error.h
//  PrinterSDK
//
//  Created by ldc on 2025/6/19.
//  Copyright © 2025 Mellow. All rights reserved.
//

#import <Foundation/Foundation.h>
// 防止PTEnumList导入报错
#import <CoreBluetooth/CoreBluetooth.h>
#import <PrinterSDK/PTPrinter.h>
#import <PrinterSDK/PTEnumList.h>
#import <PrinterSDK/S1Type.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, S1ErrorCode) {
    S1ErrorCodeParams = 1,
    S1ErrorCodeUDPConfigEthDhcp = 1000,
    S1ErrorCodeUDPConfigEthIp = 1001,
    S1ErrorCodeUDPConfigEthMask = 1002,
    S1ErrorCodeUDPConfigEthGateway = 1003,
    S1ErrorCodeUDPConfigWiFiMode = 1004,
    S1ErrorCodeUDPConfigEncryption = 1005,
    S1ErrorCodeUDPConfigApName = 1006,
    S1ErrorCodeUDPConfigApPwd = 1007,
    S1ErrorCodeUDPConfigStaName = 1008,
    S1ErrorCodeUDPConfigStaPwd = 1009,
    S1ErrorCodeUDPConfigApIp = 1010,
    S1ErrorCodeUDPConfigStaIp = 1011,
    S1ErrorCodeUDPConfigWiFiDhcp = 1012,
    S1ErrorCodeUDPConfigWiFiGateway = 1013,
    S1ErrorCodeUDPConfigWiFiMask = 1014,
    S1ErrorCodeBleTimeout                  = 2000, ///< \~chinese 蓝牙连接超时 \~english Bluetooth connection timed out
    S1ErrorCodeBleDisvocerServiceTimeout   = 2001, ///< \~chinese 获取服务超时 \~english Get service timed out
    S1ErrorCodeBleValidateTimeout          = 2002, ///< \~chinese 验证超时 \~english Print Verification timed out
    S1ErrorCodeBleUnknownDevice            = 2003, ///< \~chinese 未知设备 \~english Unknown device
    S1ErrorCodeBleSystem                   = 2004, ///< \~chinese 系统错误 \~english System error
    S1ErrorCodeBleValidateFail             = 2005, ///< \~chinese 验证失败 \~english Verification failed
    S1ErrorCodeStreamTimeout               = 2006, ///< \~chinese 流打开超时 \~english Stream open timeout
    S1ErrorCodeStreamEmpty                 = 2007, ///< \~chinese 打开的是空流 \~english Empty stream
    S1ErrorCodeStreamOccured               = 2008,  ///< \~chinese 流发生错误 \~english An error has occurred on the stream
    S1ErrorCodeResponseResolve = 3001, // 响应解析失败
    S1ErrorCodeOtaGetMaxPackageSize = 3002, // OTA升级获取最大包大小失败
    S1ErrorCodeOtaRetryTooMuch = 3003, // OTA升级重发次数过多
    S1ErrorCodeOtaStatusLengthError = 4001, // OTA升级长度错误
    S1ErrorCodeOtaStatusCrcError, // OTA升级CRC错误
    S1ErrorCodeOtaStatusTimeOut, // OTA升级超时
    S1ErrorCodeOtaStatusWriteFail, // OTA升级写入失败
    S1ErrorCodeOtaStatusFail, // OTA升级失败
    S1ErrorCodeESCPrintFail = 5000, // ESC打印失败
    S1ErrorCodeESCPrintTimeout = 5001, // ESC打印超时
};

extern NSErrorDomain S1ErrorDomain;

extern NSErrorUserInfoKey S1InnerErrorUserInfoKey;

NSError *S1ErrorFromCode(S1ErrorCode code);

NSError *S1ErrorFromCodeWithInnerError(S1ErrorCode code, NSError * _Nullable error);

NSError *S1ErrorFromCodeWithConnectError(PTConnectError code);

NSError *S1ErrorFromCodeWithOtaStatus(S1V1ProtocolOtaStatus status);

NS_ASSUME_NONNULL_END
