package com.ruoyi.system.domain.enums.verificationCode;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 验证码类型
 * @author wjh
 * 2024/3/27
 */
@AllArgsConstructor
@Getter
public enum CodeBusinessType {

    UPDATE_PASSWORD("updatePassword", "修改密码", 6, 300, 60),
    UNBIND_MOBILE("unbindMobile", "解绑手机号", 6, 300, 60),
    CHANGE_MOBILE_OLD("changeMobileOld", "更换手机号:验证旧手机号", 6, 300, 60),
    CHANGE_MOBILE_NEW("changeMobileNew", "更换手机号:验证新手机号", 6, 300, 60),
    ;

    private final String type;
    private final String msg;
    private final Integer length;   // 验证码长度
    private final Integer expireTime;  // 过期时间（秒）
    private final Integer lockTime;    // 锁定时间（秒），多久之内无法继续获取验证码

    public static CodeBusinessType parse(String type) {
        for (CodeBusinessType obj : CodeBusinessType.values()) {
            if (Objects.equals(obj.getType(), type)) {
                return obj;
            }
        }
        String types = Arrays.stream(CodeBusinessType.values()).map(CodeBusinessType::getType).collect(Collectors.joining("、"));
        throw new RuntimeException("不存在值为" + type + "的验证码类型，可选值：" + types);
    }
}
