package cn.newfeifan.mall.module.member.controller.app.auth.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;

import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.newfeifan.mall.module.member.enums.ErrorCodeConstants.LINK_ID_IS_NOT_EXISTS;

@Schema(description = "用户 APP - 手机 + 验证码登录 Request VO,如果登录并绑定社交用户，需要传递 social 开头的参数")
@Data
public class AppAuthSmsRegisterReqVO extends AppAuthSmsLoginReqVO {

    @Schema(description = "分享链接ID")
    @NotNull(message = "只能通过分享注册")
    private String linkId;

    @Schema(description = "密码")
    @NotNull(message = "密码不能为空")
    @Length(min = 4, max = 16, message = "密码长度为 4-16 位")
    private String password;

    public Long getLinkId() {
        if (linkId == null) {
            throw exception(LINK_ID_IS_NOT_EXISTS);
        }
        return Long.parseLong(linkId,16);
    }
}