package com.apobates.forum.thrones.vo;

import com.apobates.forum.core.entity.TopicStats;
import com.apobates.forum.core.entity.proxy.TopicReplica;
import com.apobates.forum.utils.Commons;
import com.apobates.forum.utils.DateTimeUtils;
import java.io.Serializable;
import java.util.Objects;

/**
 * 会员中心的发布的话题(回复的话题)
 *
 * @author xiaofanku
 * @since 20200526
 */
public final class ForumActionRecord implements Serializable {
    private static final long serialVersionUID = 1L;
    private final String title;
    private final String link;
    private final String publisher;
    private final String publisherURI;
    private final String publishDate;
    private final boolean reply;
    private final String replier;
    private final String replierURI;
    private final String replyDate;
    
    public ForumActionRecord(TopicReplica topic) {
        Objects.requireNonNull(topic);
        
        this.title = topic.getTitle();
        this.link = String.format("/topic/%s.xhtml", topic.getConnect());
        this.publisher = topic.getMemberNickname();
        this.publisherURI = String.format("/member/%d.xhtml", topic.getMemberId());
        this.publishDate = DateTimeUtils.formatClock(topic.getEntryDateTime());
        TopicStats ts = topic.getStats();
        if (null != ts) {
            this.replier = ts.getRecentPostsMemberNickname();
            this.replierURI = String.format("/member/%d.xhtml", ts.getRecentPostsMemberId());
            this.replyDate = DateTimeUtils.formatClock(ts.getRecentPostsDate());
            this.reply = Commons.isNotBlank(ts.getRecentPostsMemberNickname());
        } else {
            this.replier = "";
            this.replierURI = "";
            this.replyDate = "-";
            this.reply = false;
        }
    }
    
    public boolean isReply() {
        return reply;
    }
    
    public String getTitle() {
        return title;
    }
    
    public String getLink() {
        return link;
    }
    
    public String getPublisher() {
        return publisher;
    }
    
    public String getPublisherURI() {
        return publisherURI;
    }
    
    public String getPublishDate() {
        return publishDate;
    }
    
    public String getReplier() {
        return replier;
    }
    
    public String getReplierURI() {
        return replierURI;
    }
    
    public String getReplyDate() {
        return replyDate;
    }
}