package com.dji.sdk.cloudapi.device;

import com.dji.sdk.exception.CloudSDKException;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.Arrays;

/**
 * @author sean
 * @version 1.4
 * @date 2023/3/9
 */
public enum DroneModeCodeEnum {

    IDLE(0,"待机"),

    TAKEOFF_PREPARE(1,"起飞准备"),

    TAKEOFF_FINISHED(2,"起飞准备完毕"),

    MANUAL(3,"手动飞行"),

    TAKEOFF_AUTO(4,"自动起飞"),

    WAYLINE(5,"航线飞行"),

    PANORAMIC_SHOT(6,"全景拍照"),

    ACTIVE_TRACK(7,"智能跟随"),

    ADS_B_AVOIDANCE(8,"躲避"),

    RETURN_AUTO(9,"自动返航"),

    LANDING_AUTO(10,"自动降落"),

    LANDING_FORCED(11,"强制降落"),

    LANDING_THREE_PROPELLER(12,"三桨叶降落"),

    UPGRADING(13,"升级中"),

    DISCONNECTED(14,"未连接"),

    APAS(15,"APAS"),

    VIRTUAL_JOYSTICK(16,"虚拟摇杆状态"),

    LIVE_FLIGHT_CONTROLS(17,"指令飞行"),

    AERIAL_RTK_FIXED(18,"空中 RTK 收敛模式"),

    DOCK_SITE_EVALUATION(19,"机场选址中"),

    POI(20,"POI环绕"),

    ;

    private final int code;

    private final String text;

    DroneModeCodeEnum(int code, String text) {
        this.code = code;
        this.text = text;
    }

    @JsonValue
    public int getCode() {
        return code;
    }

    public String getText() {
        return text;
    }

    @JsonCreator
    public static DroneModeCodeEnum find(int code) {
        return Arrays.stream(values()).filter(modeCodeEnum -> modeCodeEnum.ordinal() == code).findAny()
                .orElseThrow(() -> new CloudSDKException(DroneModeCodeEnum.class, code));
    }
}
