package com.apobates.forum.core.entity;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Map;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

/**
 * 版块统计
 *
 * @author xiaofanku
 * @since 20200510
 */
@Entity
@Table(name = "apo_board_stats", uniqueConstraints={@UniqueConstraint(columnNames={"boardId"})})
public class BoardStats implements Serializable {
    private static final long serialVersionUID = 8660609463251710032L;
    @Id
    private long boardId;
    //卷的ID
    private int volumesId;
    //话题数
    private long topices;
    //回复数
    private long postses;
    //收藏数
    private long favorites;
    //最近发布的话题标题
    private String recentTopicTitle;
    //最近发布的话题ID
    private long recentTopicId;
    //最近发布的话题时间
    private LocalDateTime recentTopicDate;
    //最近发布的话题作者ID
    private long recentTopicMemberId;
    //最近发布的话题作者帐号
    private String recentTopicMemberNickname;
    //统计更新的时间
    private LocalDateTime updateDate;
    //今天的话题数|数据库中不存在
    @Transient
    private long todayTopices = 0L;

    //empty constructor for JPA instantiation
    public BoardStats() {
        super();
    }
    //创建版块时
    public BoardStats(long boardId, int volumesId) {
        this.boardId = boardId;
        this.volumesId = volumesId;
        //
        this.topices = 0;
        this.postses = 0;
        this.favorites = 0;
        
        this.recentTopicTitle = null;
        this.recentTopicId = 0L;
        this.recentTopicDate = null;
        this.recentTopicMemberId = 0L;
        this.recentTopicMemberNickname = null;
        this.updateDate = LocalDateTime.now();
    }
    
    public long getBoardId() {
        return boardId;
    }
    
    public int getVolumesId() {
        return volumesId;
    }
    
    public long getTopices() {
        return topices;
    }
    
    public long getPostses() {
        return postses;
    }
    
    public long getFavorites() {
        return favorites;
    }
    
    public String getRecentTopicTitle() {
        return recentTopicTitle;
    }
    
    public long getRecentTopicId() {
        return recentTopicId;
    }
    
    public LocalDateTime getRecentTopicDate() {
        return recentTopicDate;
    }
    
    public long getRecentTopicMemberId() {
        return recentTopicMemberId;
    }
    
    public String getRecentTopicMemberNickname() {
        return recentTopicMemberNickname;
    }
    
    public LocalDateTime getUpdateDate() {
        return updateDate;
    }
    
    public long getTodayTopices() {
        return todayTopices;
    }
    
    public void setBoardId(long boardId) {
        this.boardId = boardId;
    }
    
    public void setVolumesId(int volumesId) {
        this.volumesId = volumesId;
    }
    
    public void setTopices(long topices) {
        this.topices = topices;
    }
    
    public void setPostses(long postses) {
        this.postses = postses;
    }
    
    public void setFavorites(long favorites) {
        this.favorites = favorites;
    }
    
    public void setRecentTopicTitle(String recentTopicTitle) {
        this.recentTopicTitle = recentTopicTitle;
    }
    
    public void setRecentTopicId(long recentTopicId) {
        this.recentTopicId = recentTopicId;
    }
    
    public void setRecentTopicDate(LocalDateTime recentTopicDate) {
        this.recentTopicDate = recentTopicDate;
    }
    
    public void setRecentTopicMemberId(long recentTopicMemberId) {
        this.recentTopicMemberId = recentTopicMemberId;
    }
    
    public void setRecentTopicMemberNickname(String recentTopicMemberNickname) {
        this.recentTopicMemberNickname = recentTopicMemberNickname;
    }
    
    public void setUpdateDate(LocalDateTime updateDate) {
        this.updateDate = updateDate;
    }
    
    public void setTodayTopices(long todayTopices) {
        this.todayTopices = todayTopices;
    }
    @Transient
    public Map<String, Long> statsMap() {
        return Map.ofEntries(Map.entry("threads", getTopices()), Map.entry("replies", getPostses()), Map.entry("favorites", getFavorites()));
    }
}