package cz.vavru.test.dwr.domain;

import java.io.Serializable;
import java.util.Date;

/**
 * 
 * @author vlastimil@vavru.cz (http://vavru.cz)
 * 
 */
public class Message implements Serializable {
	static final long serialVersionUID = -7034897190745766939L;

	private int messageId;
	private String message;
	private User sender;
	private User recipient;
	private Date date;

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public long getTime() {
		return date.getTime();
	}

	public int getMessageId() {
		return messageId;
	}

	public void setMessageId(int messageId) {
		this.messageId = messageId;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if ((obj == null) || (obj.getClass() != this.getClass()))
			return false;

		Message test = (Message) obj;
		return sender.equals(test.getSender()) && recipient == test.getRecipient()
				&& (message != null && message.equals(test.getMessage()))
				&& date.equals(test.getDate());
	}

	@Override
	public int hashCode() {
		return (int) (5 * sender.hashCode() + 12 * (recipient != null ? recipient.hashCode() : 0)
				+ date.hashCode() + message.hashCode());
	}

	@Override
	public String toString() {
		return this.getClass().getName() + ": messageId - " + messageId + ", senderId - "
				+ sender.getUserId() + ", recipientId - "
				+ (recipient != null ? recipient.getUserId() : "null") + ", date - " + date
				+ ", text - " + message;
	}

	public User getSender() {
		return sender;
	}

	public void setSender(User sender) {
		this.sender = sender;
	}

	public User getRecipient() {
		return recipient;
	}

	public void setRecipient(User recipient) {
		this.recipient = recipient;
	}

}
