package fr.insa.clavardator.lib.message;

import fr.insa.clavardator.lib.users.User;
import fr.insa.clavardator.lib.users.UserInformation;

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

public class Message implements Serializable, SenderInfo, RecipientInfo {
	private final String text;
	private final Date date;
	private final UserInformation sender;
	private final UserInformation recipient;

	public Message(UserInformation sender, UserInformation recipient, Date date) {
		this(sender, recipient, date, "");
	}

	public Message(User sender, User recipient, Date date) {
		this(sender, recipient, date, "");
	}

	public Message(UserInformation sender, UserInformation recipient, Date date, String text) {
		this.sender = sender;
		this.recipient = recipient;
		this.date = date;
		this.text = text;
	}

	public Message(User sender, User recipient, Date date, String text) {
		this.sender = new UserInformation(sender);
		this.recipient = new UserInformation(recipient);
		this.date = date;
		this.text = text;
	}

	public String getText() {
		return text;
	}

	public UserInformation getSender() {
		return sender;
	}

	public UserInformation getRecipient() {
		return recipient;
	}

	public Date getDate() {
		return date;
	}

	@Override
	public String toString() {
		return "Message{" +
				"text='" + text + '\'' +
				", date=" + date +
				", sender=" + sender +
				", recipient=" + recipient +
				'}';
	}

	@Override
	public String getSenderId() {
		return sender.id;
	}

	@Override
	public String getRecipientId() {
		return recipient.id;
	}
}
