package com.crunii.micro.common.enums;

import com.crunii.micro.common.exception.BusinessException;

/**
 * @author lmlksy
 * @date 2023/11/22 15:26
 */
public enum ResultEnums {

    SUCCESS(1, "成功"),
    FAILURE(0, "失败");

    private final Integer code;
    private final String description;

    ResultEnums(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    public Integer getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static String getByCode(Integer code) {
        for (ResultEnums result : values()) {
            if (result.getCode() != null && result.getCode().equals(code)) {
                return result.getDescription();
            }
        }
       return null;
    }
    public static Integer getByDescription(String description) {
        for (ResultEnums status : values()) {
            if (status.getDescription().equals(description)) {
                return status.getCode();
            }
        }
        return null;
    }
}
