package com.ningdatech.pmapi.sms.constant;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

/**
 * @author liuxinxin
 * @date 2023/2/16 下午4:50
 */

@Getter
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "VerificationCodeType", description = "验证码类型")
public enum VerificationCodeType {

    /**
     * 用户注册
     */
    LOGIN("用户登录", 1, 5, 10);

    @ApiModelProperty(value = "描述")
    private String desc;

    @ApiModelProperty(value = "发送间隔（单位：分钟）")
    private Integer sendInterval;

    @ApiModelProperty(value = "过期时间（单位：分钟）")
    private Integer expireTime;

    /**
     * 小于等于0则不限制次数,超出次数限制则锁定验证码发送
     */
    @ApiModelProperty(value = "每日发送次数")
    private Integer sendTimesByDay;


    public static VerificationCodeType match(String val, VerificationCodeType def) {
        return Stream.of(values()).filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static VerificationCodeType get(String val) {
        return match(val, null);
    }

    public boolean eq(VerificationCodeType val) {
        return val != null && this.name().equals(val.name());
    }

    @ApiModelProperty(value = "编码")
    public String getCode() {
        return this.name();
    }

    public static VerificationCodeType of(String key) {
        for (VerificationCodeType statusEnum : VerificationCodeType.values()) {
            if (statusEnum.name().equals(key)) {
                return statusEnum;
            }
        }
        throw new IllegalArgumentException(String.format("Illegal VerificationCodeType = %s", key));
    }
}
