package com.zfire.mall.manager.enums;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum IsEnum {
    YES(true,"是"),
    NO(false,"否");

    @JsonValue
    @EnumValue
    private final Boolean key;
    private final String value;


    public static IsEnum findEnumByKey(Boolean key) {
        IsEnum[] values = IsEnum.values();
        for (IsEnum isEnum : values) {
            if (isEnum.getKey().equals(key)) {
                return isEnum;
            }
        }
        return null;
    }

    public static Boolean findKeyByValue(String value) {
        IsEnum[] enums = IsEnum.values();
        for (IsEnum anEnum : enums) {
            boolean b = anEnum.getValue().equals(StrUtil.trim(value));
            if (b)
                return anEnum.getKey();
        }
        return null;
    }

}
