package CK.IA;

public class Message {
	/**
	 * Message identifier counter. Makes sure all messages have unique identifiers.
	 */
	private static int id_counter = 0;

	public static int getId_counter() {
		return id_counter;
	}

	/**
	 * The content of the message
	 */
	private Object content;
	/**
	 * The identifier of the message receiver
	 * 
	 */
	private int destination_id;
	/**
	 * Internal identifier for the message (unique). I have a feeling for it being a 32-bit signed integer, it won't last too long...
	 */
	private int id;
	/**
	 * The performative of the message
	 * 
	 */
	private Performative performative;
	/**
	 * The property of the subject(s) regarding the message
	 * 
	 */
	private Property property;
	/**
	 * The identifier of the message sender
	 * 
	 */
	private int sender_id;

	/**
	 * The subject(s) of the message
	 * 
	 */
	private Subject subject;

	/**
	 * The identifier of the subject (if only one)
	 * 
	 */
	private int subject_id;

	/**
	 * Constructs a new message
	 * 
	 * @param performative
	 *            The performative of the message
	 * @param subject
	 *            The subject(s) of the message
	 * @param property
	 *            The property of the subject(s) regarding the message
	 * @param subject_id
	 *            The identifier of the subject (if only one)
	 * @param destination_id
	 *            The identifier of the message receiver
	 * @param sender_id
	 *            The identifier of the message sender
	 */
	public Message(Performative performative, Subject subject, Property property, int subject_id, int destination_id, int sender_id) {
		this.setSender_id(sender_id);
		this.setDestination_id(destination_id);
		this.setContent(null);
		this.setPerformative(performative);
		this.setSubject(subject);
		this.setProperty(property);
		this.setSubject_id(subject_id);
		this.id = id_counter;
		id_counter++;
		// wrap integer limit
		if (id_counter >= Integer.MAX_VALUE)
			id_counter = 0;
		// System.out.println(id_counter);
	}

	public Object getContent() {
		return content;
	}

	public int getDestination_id() {
		return destination_id;
	}

	public int getId() {
		return id;
	}

	public Performative getPerformative() {
		return performative;
	}

	public Property getProperty() {
		return property;
	}

	public int getSender_id() {
		return sender_id;
	}

	public Subject getSubject() {
		return subject;
	}

	public int getSubject_id() {
		return subject_id;
	}

	public void setContent(Object content) {
		this.content = content;
	}

	public void setDestination_id(int destination_id) {
		this.destination_id = destination_id;
	}

	public void setPerformative(Performative performative) {
		this.performative = performative;
	}

	public void setProperty(Property property) {
		this.property = property;
	}

	public void setSender_id(int sender_id) {
		this.sender_id = sender_id;
	}

	public void setSubject(Subject subject) {
		this.subject = subject;
	}

	public void setSubject_id(int subject_id) {
		this.subject_id = subject_id;
	}

	public String toString() {
		return "Id:" + this.getId() + "|Performative:" + this.getPerformative() + "|Subject:" + this.getSubject() + "|Property:" + this.getProperty()
				+ "|Subject Id:" + this.getSubject_id() + "|Destination Id:" + this.getDestination_id() + "|Sender Id:" + this.getSender_id()
				+ "|Content:" + this.getContent();
	}

}
