package com.apobates.forum.letterbox.entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 * 发件箱
 *
 * @author xiaofanku
 * @since 20200510
 */
@Entity
@Table(name = "apo_letter_outbox", uniqueConstraints = {@UniqueConstraint(columnNames = {"member", "receiver", "letter"})})
public class Outbox implements Serializable {
    private static final long serialVersionUID = -6091096592336558464L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private long id;
    //会员id
    private long member;
    //收件人/会员ID
    private long receiver;
    private String receiverNickname;
    //是否可用:false(0)已删除,true(1)可用
    @Column(columnDefinition="tinyint(1) default 0")
    private boolean status;
    //信件ID
    private long letter;

    //empty constructor for JPA instantiation
    public Outbox() {
    }
    public Outbox(long letterAuthor, long receiver, String receiverNickname, long letterId) {
        this.member = letterAuthor;
        this.receiver = receiver;
        this.receiverNickname = receiverNickname;
        this.letter = letterId;
        this.status = true;
    }
    public long getId() {
        return id;
    }
    
    public long getMember() {
        return member;
    }
    
    public long getReceiver() {
        return receiver;
    }
    
    public String getReceiverNickname() {
        return receiverNickname;
    }
    
    public boolean isStatus() {
        return status;
    }
    
    public long getLetter() {
        return letter;
    }
    
    public void setId(long id) {
        this.id = id;
    }
    
    public void setMember(long member) {
        this.member = member;
    }
    
    public void setReceiver(long receiver) {
        this.receiver = receiver;
    }
    
    public void setReceiverNickname(String receiverNickname) {
        this.receiverNickname = receiverNickname;
    }
    
    public void setStatus(boolean status) {
        this.status = status;
    }
    
    public void setLetter(long letter) {
        this.letter = letter;
    }
    
    @Override
    public int hashCode() {
        int hash = 5;
        hash = 89 * hash + (int) (this.member ^ (this.member >>> 32));
        hash = 89 * hash + (int) (this.receiver ^ (this.receiver >>> 32));
        hash = 89 * hash + (int) (this.letter ^ (this.letter >>> 32));
        return hash;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Outbox other = (Outbox) obj;
        if (this.member != other.member) {
            return false;
        }
        if (this.receiver != other.receiver) {
            return false;
        }
        if (this.letter != other.letter) {
            return false;
        }
        return true;
    }
}