package com.dji.sdk.cloudapi.firmware;

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 FirmwareErrorCodeEnum implements IServicesErrorCode, IEventsErrorCode, IErrorInfo {

    WRONG_TYPE(312001, "已触发一致性升级，但设备未请求"),

    READY_1_FAILED(312002, "升级失败。请再试一次"),

    VALIDATION_FAILED(312003, "升级失败。请再试一次"),

    READY_2_FAILED(312004, "升级失败。请再试一次"),

    WRONG_PROTOCOL(312010, "升级请求与升级命令不一致"),

    WRONG_PARAMETER(312012, "请检查参数后重试"),

    COMMAND_1_FAILED(312013, "升级失败。请再试一次"),

    UPDATING(312014, "设备升级中，请勿重复操作"),

    WORKING(312015, "机场：{dock_org_name} 业务繁忙无法进行设备升级，请等待机场处于空闲中后再试"),

    TRANSMISSION_ERROR(312016, "升级失败，机场和飞行器图传链路异常，请重启机场和飞行器后重试"),

    VERSION_CHECK_FAILED(312017, "版本检查失败"),

    COMMAND_2_FAILED(312018, "升级失败。请再试一次"),

    COMMAND_3_FAILED(312019, "升级失败。请再试一次"),

    COMMAND_4_FAILED(312020, "升级失败。请再试一次"),

    COMMAND_5_FAILED(312021, "升级失败。请再试一次"),

    AIRCRAFT_NOT_FOUND(312022, "飞行器开机失败或未连接，请检查飞行器是否在舱内，是否安装电池，机场和飞行器是否已对频"),

    AIRCRAFT_OUTSIDE(312023, "推杆闭合失败无法升级飞行器，请检查急停按钮是否被按下，推杆是否有异物卡住"),

    COMMAND_6_FAILED(312024, "升级失败。请再试一次"),

    DELETE_FAILED(312025, "删除旧固件包失败"),

    DECOMPRESSION_FAILED(312026, "解压离线升级包失败"),

    NO_AIRCRAFT_DETECTED(312027, "升级失败，机场未检测到飞行器"),

    DEVICE_RESTART_1(312028, "升级失败，设备升级过程中设备被重启"),

    DEVICE_RESTART_2(312029, "设备重启中无法进行设备升级，请等待设备重启完成后重试"),

    FOURTH_GENERATION_IS_ENABLE(312030, "升级失败，飞行器增强图传开启后无法升级，请关闭飞行器增强图传后重试"),

    LOW_POWER(312704, "设备电量过低，请充电至20%以上后重试"),

    UNKNOWN(-1, "UNKNOWN"),
    ;


    private final String msg;

    private final int code;

    FirmwareErrorCodeEnum(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 FirmwareErrorCodeEnum find(int code) {
        return Arrays.stream(values()).filter(codeEnum -> codeEnum.code == code).findAny().orElse(UNKNOWN);
    }

}
