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

import cn.newfeifan.mall.framework.common.validation.Mobile;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;
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 {

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

    @Schema(description = "分享链接ID")
    @NotNull(message = "用户名不能为空")
    private String username;

    @Schema(description = "手机号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15601691300")
    @NotEmpty(message = "手机号不能为空")
    @Mobile
    private String mobile;

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

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