package com.njzscloud.supervisory.sys.user.pojo.param;

import cn.hutool.core.util.StrUtil;
import com.njzscloud.common.mvc.validator.Constrained;
import com.njzscloud.common.mvc.validator.Constraint;
import com.njzscloud.common.mvc.validator.ValidRule;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;

@Getter
@Setter
@Constraint
@Accessors(chain = true)
public class AddUserAccountParam implements Constrained {
    /**
     * 用户 Id; sys_user.id
     */
    private Long userId;
    /**
     * 用户名
     */
    @NotBlank(message = "用户名不能为空")
    private String username;
    /**
     * 邮箱
     */
    private String email;
    /**
     * 手机号
     */
    private String phone;
    /**
     * 密码
     */
    @NotBlank(message = "密码不能为空")
    private String secret;
    /**
     * 微信 openid
     */
    private String wechatOpenid;
    /**
     * 微信 unionid
     */
    private String wechatUnionid;
    /**
     * 允许登录的客户端; 字典代码：client_code
     */
    private Integer clientCode;
    /**
     * 是否禁用; 0-->启用、1-->禁用
     */
    private Boolean disabled;


    @Override
    public ValidRule[] rules() {
        return new ValidRule[]{
                // ValidRule.of(() -> StrUtil.isNotBlank(username), "用户名不能为空"),
                // ValidRule.of(() -> StrUtil.isNotBlank(secret), "密码不能为空"),
                ValidRule.of(() -> (StrUtil.isNotBlank(wechatOpenid) && StrUtil.isNotBlank(wechatUnionid)) ||
                        (StrUtil.isBlank(wechatOpenid) && StrUtil.isBlank(wechatUnionid)), "微信账号不正确"),
        };
    }

}
