package com.ruoyi.common.exception.user;

import com.ruoyi.common.enums.IIntegerEnum;

import java.util.Objects;

/**
 * 用户信息异常类
 *
 * @author ruoyi
 */
public enum ApiUserException implements IIntegerEnum {

    // TODO 注意检查错误码，保证系统内唯一
    USER_NOT_EXISTS(100001, "用户不存在"),
    USER_IS_NOT_TEACHER(100002, "用户不是老师"),
    USER_IS_NOT_WORKER(100003, "用户不是护工");

    private Integer code;

    private String msg;

    ApiUserException(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static ApiUserException getByCode(int code) {
        for (ApiUserException value : ApiUserException.values()) {
            if (Objects.equals(code, value.getCode())) {
                return value;
            }
        }
        return null;
    }

}
