package cn.reghao.autodop.dmaster.rbac.model.dto;

import cn.reghao.autodop.dmaster.rbac.model.po.User;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Set;

/**
 * @author reghao
 * @date 2021-09-13 17:12:59
 */
@Data
public class UserAddDTO implements Serializable {
    private static final long serialVersionUID = 1L;

    // 用户名和密码
    @NotBlank(message = "登录名不能为空白字符串")
    private String username;
    @NotBlank(message = "密码不能为空白字符串")
    private String password;
    @NotEmpty(message = "必须指定角色")
    @Size(min = 1, max = 1, message = "只能指定一个角色")
    private Set<Integer> roleIds;

    @NotBlank(message = "用户名不能为空白字符串")
    private String nickname;
    private int gender;
    private String mobilePhone;
    private String email;

    public User to() {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        //user.setRoleIds(roleIds);
        user.setNickname(nickname);
        user.setGender(gender);
        user.setMobilePhone(mobilePhone);
        user.setEmail(email);
        return user;
    }
}
