package com.dji.sdk.cloudapi.control;

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

    SETTING_RTH_FAILED(327000, "返航高度设置失败，请稍候重试"),

    SETTING_LOST_ACTION_FAILED(327001, "失联动作设置失败，请稍候重试"),

    OBTAIN_CONTROL_FAILED(327002, "获取控制权失败，请稍后重试"),

    DEVICE_OFFLINE(327003, "获取控制权失败，请稍后重试"),

    DRAG_LIVESTREAM_VIEW_FAILED(327004, "画面拖动失败，请重试"),

    AIM_FAILED(327005, "双击画面归中失败"),

    TAKE_PHOTO_FAILED(327006, "拍照失败"),

    START_RECORDING_FAILED(327007, "开始录像失败"),

    STOP_RECORDING_FAILED(327008, "停止录像失败"),

    SWITCH_CAMERA_MODE_FAILED(327009, "切换相机模式失败"),

    ZOOM_CAMERA_ZOOM_FAILED(327010, "ZOOM相机变焦失败"),

    IR_CAMERA_ZOOM_FAILED(327011, "IR相机变焦失败"),

    DEVICE_LOCK(327012, "获取控制权失败，请稍后重试"),

    SETTING_WAYLINE_LOST_ACTION_FAILED(327013, "参数设置失败，请稍后重试"),

    GIMBAL_REACH_LIMIT(327014, "云台已达限位"),

    WRONG_LENS_TYPE(327015, "直播启动失败，建议刷新直播或重新打开设备小窗"),


    DRC_ABNORMAL(514300, "DRC 异常"),

    DRC_HEARTBEAT_TIMED_OUT(514301, "DRC 心跳超时"),

    DRC_CERTIFICATE_ABNORMAL(514302, "DRC 网络证书异常，连接失败"),

    DRC_LINK_LOST(514303, "DRC 网络异常，连接断开"),

    DRC_LINK_REFUSED(514304, "DRC 请求被拒，连接失败"),

    UNKNOWN(-1, "UNKNOWN"),

    ;


    private final String msg;

    private final int code;

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

}
