package com.zcxk.rmcp.api.enums;

import com.zcxk.core.utils.ZoniotStringUtils;
import io.swagger.models.auth.In;
import lombok.Getter;

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

/**
 * @author Andy
 * @description 抄表状态/读表状态
 * @date 2021-07-20 11:40
 */
@Getter
public enum ReadStatusEnum {

    /**
     * 未抄
     */
    UN_READ(1, "未抄"),

    /**
     * 已抄
     */
    READ(2, "已抄"),

    ;

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

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


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


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

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