package com.apobates.forum.core.entity;

import com.apobates.forum.event.elderly.ActionEventCulpritor;
import com.apobates.forum.event.elderly.ForumActionEnum;
import java.time.LocalDateTime;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

/**
 * 话题的操作集合
 * 
 * @author xiaofanku
 * @since 20200514
 */
@Entity
@DiscriminatorValue("T")
public class TopicActionCollection extends ActionEventDescriptor{
    private static final long serialVersionUID = 1L;
    //话题的标题
    protected String topicTitle;
    //话题的ID
    protected long topicId;
    //话题类操作时,postsId=0
    protected long postsId;
    
    //empty constructor for JPA instantiation
    public TopicActionCollection() {
        super();
    }
    /**
     * 话题操作
     * @param memberNames 动作的操作会员昵称
     * @param memberId 动作的操作会员ID
     * @param action 动作
     * @param topicTitle 动作关联的话题标题
     * @param topicId 动作关联的话题ID
     * @param postsId 动作关联的回复ID
     * @param ipAddr 操作会员使用的ip
     * @param token 操作绑定的token
     * @param rodeMember 积分计算时的受益会员ID
     */
    public TopicActionCollection(
            String memberNames, 
            long memberId, 
            ForumActionEnum action, 
            String topicTitle, 
            long topicId, 
            long postsId, 
            String ipAddr, 
            String token, 
            long rodeMember) {
        super(memberNames, memberId, action, LocalDateTime.now(), ipAddr, token, rodeMember);
        this.topicTitle = topicTitle;
        this.topicId = topicId;
        this.postsId = postsId;
    }
    /**
     * 话题操作
     * @param action 动作
     * @param topicTitle 动作关联的话题标题
     * @param topicId 动作关联的话题ID
     * @param postsId 动作关联的回复ID
     * @param culpritor 
     * @param rodeMember 积分计算时的受益会员ID
     */
    public TopicActionCollection(
            ForumActionEnum action,
            String topicTitle,
            long topicId,
            long postsId,
            ActionEventCulpritor culpritor, 
            long rodeMember) {
        super(culpritor.getMemberNickname(), culpritor.getMemberId(), action, LocalDateTime.now(), culpritor.getIpAddr(), culpritor.getToken(), rodeMember);
        this.topicTitle = topicTitle;
        this.topicId = topicId;
        this.postsId = postsId;
    }
    
    public String getTopicTitle() {
        return topicTitle;
    }
    
    public long getTopicId() {
        return topicId;
    }
    
    public long getPostsId() {
        return postsId;
    }
    
    public void setTopicTitle(String topicTitle) {
        this.topicTitle = topicTitle;
    }
    
    public void setTopicId(long topicId) {
        this.topicId = topicId;
    }
    
    public void setPostsId(long postsId) {
        this.postsId = postsId;
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + (int) (postsId ^ (postsId >>> 32));
        result = prime * result + (int) (topicId ^ (topicId >>> 32));
        return result;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!super.equals(obj)) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        TopicActionCollection other = (TopicActionCollection) obj;
        if (postsId != other.postsId) {
            return false;
        }
        return topicId == other.topicId;
    }
}