package com.ningdatech.pmapi.todocenter.enumeration;

import java.util.Objects;

import org.apache.commons.lang3.StringUtils;

import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * 是否增补项目枚举
 *
 * @author CMM
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "IsOrNotEnum", description = "是否-枚举")
public enum IsOrNotEnum {
    /**
     * 否
     */
    NOT(0, "否"),

    /**
     * 是
     */
    IS(1, "是");


    private Integer code;
    private String desc;

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static String getDescByCode(Integer code) {
        if (Objects.isNull(code)) {
            return StringUtils.EMPTY;
        }
        for (IsOrNotEnum t : IsOrNotEnum.values()) {
            if (code.equals(t.getCode())) {
                return t.desc;
            }
        }
        return StringUtils.EMPTY;
    }

    public static IsOrNotEnum getEnumByValue(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        for (IsOrNotEnum t : IsOrNotEnum.values()) {
            if (code.equals(t.getCode())) {
                return t;
            }
        }
        return null;
    }

    public boolean eq(String val) {
        return this.name().equals(val);
    }
}
