package com.zcxk.rmcp.api.enums;

import lombok.Getter;

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

/**
 * @author Andy
 * @description 指令类型
 * @date 2021-07-20 11:40
 */
@Getter
public enum CommandTypeEnum {

    /**
     * 开阀
     */
    OPEN(1, "开阀"),

    /**
     * 关阀
     */
    CLOSE(0, "关阀"),
    ;

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

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


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

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