package cn.axzo.msg.center.common.enums;

import cn.axzo.msg.center.common.exception.ServiceException;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 人员身份类型枚举
 *
 * @author xuyaozuo
 * @since 2022/5/9 21:59
 */
@Getter
@AllArgsConstructor
public enum IdentityType implements IEnum{

    /*人员身份类型*/
    NOT_SUPPORT(0, "NOT_SUPPORT", "无效类型"),
    WORKER(1, "WORKER", "工人"),
    WORKER_LEADER(2, "WORKER_LEADER", "班组长"),
    PRACTITIONER(3, "PRACTITIONER", "从业人员"),
    REGULATOR(4, "REGULATOR", "监管人员"),
    OPERATOR(5, "OPERATOR", "运营人员"),
    ;
    @EnumValue
    @JsonValue
    private final Integer code;
    private final String message;
    private final String desc;


    public static IdentityType getIdentityType(Integer code) {
        IdentityType[] values = values();
        for (IdentityType item : values) {
            if (item.getCode().equals(code)) {
                return item;
            }
        }
        throw new ServiceException("档案身份类型不匹配 code:" + code);
    }

    public static IdentityType getIdentityType(String message) {
        IdentityType[] values = values();
        for (IdentityType item : values) {
            if (item.getMessage().equals(message)) {
                return item;
            }
        }
        throw new ServiceException("档案身份类型不匹配 message:" + message);
    }
}
