package com.ruoyi.common.enums;

import com.ruoyi.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 用户类型
 * @author 辉
 * 2024/3/8
 */
@Getter
@AllArgsConstructor
public enum UserType {

    USER("1", "普通用户"),
    MCH("2", "商户"),
    AGENT("3", "代理商");

    private final String type;
    private final String name;

    // 转换
    public static UserType parse(String type) {
        for (UserType value : UserType.values()) {
            if (value.getType().equals(type)) {
                return value;
            }
        }
        throw new ServiceException("不存在的用户类型");
    }

    public boolean equalsType(String type) {
        return Objects.equals(this.type, type);
    }

    // 判断该类型是否存在
    public static boolean contains(String type) {
        for (UserType value : UserType.values()) {
            if (value.getType().equals(type)) {
                return true;
            }
        }
        return false;
    }
}
