package com.purui.prims.auth.api.authentication.pojo;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {

    @ApiModelProperty(value = "用户ID")
    private Long id;

    @ApiModelProperty(value = "用户名")
    private String userName;

    @ApiModelProperty(value = "用户昵称")
    private String displayName;

    @ApiModelProperty(value = "用户邮箱")
    private String email;

    @ApiModelProperty(value = "是否管理员")
    private Integer isAdmin;

    @ApiModelProperty(value = "角色ID")
    private Integer roleId;

    @ApiModelProperty(value = "角色名称")
    private String roleName;

    @ApiModelProperty(value = "手机号")
    private String mobile;

    public static User get(Long id, String name, String displayName, String email, Integer isAdmin, Integer roleId, String roleName) {
        return new User(id, name, displayName, email, isAdmin, roleId, roleName, "");
    }

    public static User get(Long id, String name) {
        return new User(id, name, name, name, 0, 0, "", "");
    }

    public static User getFakeUser() {
        return new User(1L, "admin", "admin", "admin@email", 1, 1, "", "");
    }

    public static User getAppUser(int appId) {
        String name = String.format("app_%s", appId);
        return new User(1L, name, name, "", 1, 1, "", "");
    }

    public String getDisplayName() {
        return StringUtils.isBlank(displayName) ? userName : displayName;
    }

    public boolean isSuperAdmin() {
        return isAdmin != null && isAdmin == 1;
    }

}
