package com.zcxk.rmcp.api.enums;

import io.swagger.models.auth.In;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author Andy
 * @description 指令状态 0:发送、1:超时、2:成功、3:失败
 * @date 2021-07-20 11:40
 */
@Getter
public enum CommandStatusEnum {

    /**
     * 发送
     */
    SEND_OUT(0, "发送"),

    /**
     * 超时
     */
    OVER_TIME(1, "超时"),

    /**
     * 成功
     */
    SUCCESS(2, "成功"),

    /**
     * 失败
     */
    FAIL(3, "失败"),
    ;

    /**
     * code
     */
    private final Integer code;

    /**
     * 说明
     */
    private final String message;


    CommandStatusEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }


    public static String getMessage(Integer code) {
        Optional<CommandStatusEnum> optional = Arrays.stream(CommandStatusEnum.values())
                .filter(p -> p.getCode().equals(code) )
                .findFirst();
        return optional.get().getMessage();
    }

    public static String getMessage(String code) {
        Optional<CommandStatusEnum> optional = Arrays.stream(CommandStatusEnum.values())
                .filter(p -> p.getCode().equals(Integer.parseInt(code)))
                .findFirst();
        return optional.get().getMessage();
    }
}
