package cn.reghao.oss.console.account.model.dto;

import cn.reghao.oss.console.account.model.po.Role;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.Pattern;

/**
 * @author reghao
 * @date 2021-07-14 14:14:07
 */
@NoArgsConstructor
@Data
public class RoleDTO {
    private Integer roleId;
    @Pattern(regexp = "^\\w+$", message = "角色只能是数字、英文字符和下划线")
    private String name;
    @Length(max = 100, message = "描述的长度不超过 100 个中文字符")
    private String description;
    private String createTime;

    public Role to() {
        Role role = new Role();
        if (this.getRoleId() != null) {
            role.setId(this.getRoleId());
        }

        role.setName("ROLE_" + this.getName());
        role.setDescription(this.getDescription());
        return role;
    }
}
