package cn.reghao.bnt.web.admin.model.dto;

import cn.reghao.bnt.web.admin.model.po.User;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;
import java.util.Locale;

/**
 * @author reghao
 * @date 2024-01-29 13:41:46
 */
@Setter
@Getter
public class AccountInfo implements Serializable {
    private static final long serialVersionUID = 1L;

    private long userId;
    private String userIdStr;
    private String username;
    private String avatarUrl;
    private String msgCount;
    private List<String> roles;

    public AccountInfo(User user) {
        this.userId = user.getId();
        this.userIdStr = "";
        this.username = user.getUsername();
        this.avatarUrl = user.getAvatarUrl();
        this.msgCount = "0";
        this.roles = user.getRole().stream()
                .map(role -> role.replace("ROLE_", "").toLowerCase(Locale.ROOT))
                .toList();
    }

    public void setMsgCount(String msgCount) {
        this.msgCount = msgCount;
    }
}
