package cn.reghao.tnb.content.app.chat.model.dto.chat;

import cn.reghao.jutil.jdk.converter.DateTimeConverter;
import cn.reghao.tnb.content.app.chat.model.dto.message.CodeBlockResult;
import cn.reghao.tnb.content.app.chat.model.dto.message.FileMsgResult;
import cn.reghao.tnb.content.app.chat.model.po.chat.ChatRecord;
import cn.reghao.tnb.user.api.dto.ContactDetail;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

/**
 * @author reghao
 * @date 2022-04-17 16:18:18
 */
@NoArgsConstructor
@Getter
@Setter
public class ChatRecordGetRet implements Serializable {
    private static final long serialVersionUID = 1L;

    private long recordId;
    private int talkType;
    private long receiverId;
    private boolean isMark;
    private boolean isRead;
    private boolean isRevoke;
    private String createdAt;
    private int msgType;
    // TODO 根据 MsgType 来确定
    private String content;
    private CodeBlockResult codeBlock;
    private FileMsgResult file;

    private String userId;
    private String nickname;
    private String avatar;

    public ChatRecordGetRet(ChatRecord chatRecord, ContactDetail contactDetail) {
        this.recordId = chatRecord.getRecordId();
        this.talkType = chatRecord.getChatType();
        this.userId = contactDetail.getUserId();
        this.receiverId = chatRecord.getReceiverId();
        this.msgType = chatRecord.getMsgType();
        this.isMark = false;
        this.isRead = chatRecord.isRead();
        this.isRevoke = chatRecord.isRevoke();
        this.nickname = contactDetail.getScreenName();
        this.avatar = contactDetail.getAvatarUrl();
        this.createdAt = DateTimeConverter.format(chatRecord.getCreateTime());
    }
}
