package com.dji.sdk.cloudapi.log;

import com.dji.sdk.common.IErrorInfo;
import com.dji.sdk.mqtt.events.IEventsErrorCode;
import com.dji.sdk.mqtt.services.IServicesErrorCode;

import java.util.Arrays;

/**
 * @author sean.zhou
 * @version 0.1
 * @date 2021/11/25
 */
public enum LogErrorCodeEnum implements IServicesErrorCode, IEventsErrorCode, IErrorInfo {

    DEVICE_RESTART(324001, "设备重启导致日志导出中断"),

    EXPORT_TIMEOUT(324012, "日志压缩过程超时，所选日志过多，请减少选择的日志后重试"),

    PULL_FAILED(324013, "设备日志列表获取失败，请稍后重试"),

    EMPTY_LOG_LIST(324014, "设备日志列表为空，请刷新页面或重启机场后重试"),

    AIRCRAFT_SHUTDOWN(324015, "飞行器已关机或未连接，无法获取日志列表，请确认飞行器在舱内，通过远程调试将飞行器开机后重试"),

    INSUFFICIENT_STORAGE_SPACE(324016, "机场存储空间不足，日志压缩失败，请清理机场存储空间或稍后重试"),

    NO_LOG(324017, "日志压缩失败，无法获取所选飞行器日志，请刷新页面或重启机场后重试"),

    COMPRESSION_FAILED(324018, "日志文件拉取失败，导致本次设备异常反馈上传失败，请稍后重试或重启机场后重试"),

    UPLOAD_FAILED(324019, "因机场网络异常，日志上传失败，请稍后重试。如果连续多次出现该问题，请联系代理商或大疆售后进行网络排障"),

    UNKNOWN(-1, "UNKNOWN"),

    ;


    private final String msg;

    private final int code;

    LogErrorCodeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public String getMessage() {
        return this.msg;
    }

    @Override
    public Integer getCode() {
        return this.code;
    }

    /**
     * @param code error code
     * @return enumeration object
     */
    public static LogErrorCodeEnum find(int code) {
        return Arrays.stream(values()).filter(codeEnum -> codeEnum.code == code).findAny().orElse(UNKNOWN);
    }

}
