package com.bonus.common.biz.enums;

import lombok.Getter;

import java.util.Objects;

/**
 * @author bonus
 */

@Getter
public enum MaStatusEnum {

    TO_BE_LISTED(0, "草稿"),
    ON_HIRE(1, "在库"),
    LISTING(2, "自用中"),
    UNDER_RENT(3,"共享中"),
    OWN(4,"退役"),
    REPAIR(5, "维修中");

    private final Integer code;
    private final String name;

    MaStatusEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 根据code获取name
     * @param code 枚举编码
     * @return 枚举值
     */
    public static String getNameByCode(int code) {
        MaStatusEnum[] maStatusEnums = values();
        for (MaStatusEnum maStatusEnum : maStatusEnums) {
            if (maStatusEnum.getCode() == code) {
                return maStatusEnum.getName();
            }
        }
        return null;
    }

    public static Integer getCodeByName(String msg) {
        MaStatusEnum[] maStatusEnums = values();
        for (MaStatusEnum maStatusEnum : maStatusEnums) {
            if (Objects.equals(maStatusEnum.getName(), msg)) {
                return maStatusEnum.getCode();
            }
        }
        return null;
    }


}
