package seedu.malitio.model.task;

import java.util.Objects;

import seedu.malitio.model.tag.UniqueTagList;

public class Event implements ReadOnlyEvent {
    private Name name;
    private DateTime start;
    private DateTime end;
    private UniqueTagList tags;
	
	public Event(Name name, DateTime start, DateTime end, UniqueTagList tags) {
		this.name = name;	
		this.start = start;
		this.end = end;
		this.tags = new UniqueTagList(tags); // protect internal tags from changes in the arg list
	}
	
    /**
     * Copy constructor.
     */
    public Event(ReadOnlyEvent source) {
        this(source.getName(), source.getStart(), source.getEnd(), source.getTags());
    }

    @Override
    public Name getName() {
        return name;
    }
    
    @Override
    public DateTime getStart() {
        return start;
    }

    @Override
    public DateTime getEnd() {
        return end;
    }


    @Override
    public UniqueTagList getTags() {
        return new UniqueTagList(tags);
    }

    /**
     * Replaces this event's tags with the tags in the argument tag list.
     */
    public void setTags(UniqueTagList replacement) {
        tags.setTags(replacement);
    }
    
    public DateTime getStartTime() {
		return start;
	}
    
    public DateTime getEndTime() {
		return end;
	}

    @Override
    public boolean equals(Object other) {
        return other == this // short circuit if same object
                || (other instanceof ReadOnlyEvent// instanceof handles nulls
                && this.isSameStateAs((ReadOnlyEvent) other));
    }

    @Override
    public int hashCode() {
        // use this method for custom fields hashing instead of implementing your own
        return Objects.hash(name, start, end, tags);
    }

    @Override
    public String toString() {
        return getAsText();
    }

}

@@ -55,16 +55,79 @@
 jects;%0A%0A
+import seedu.malitio.commons.exceptions.IllegalValueException;%0A
 import s
@@ -326,240 +326,402 @@
 ;%0A%09%0A
-%09public Event(Name name, DateTime start, DateTime end, UniqueTagList tags) %7B%0A%09%09this.name = name;%09%0A%09%09this.start = start;%0A%09%09this.end = end;%0A%09%09this.tags = new UniqueTagList(tags); // protect internal tags from changes in the arg list%0A%09
+    private final String MESSAGE_INVALID_EVENT = %22Event must start before it ends!%22;%0A%0A    public Event(Name name, DateTime start, DateTime end, UniqueTagList tags) %0A            throws IllegalValueException %7B%0A        %0A       if(!isValidEvent(start, end)) %7B       %0A           throw new IllegalValueException(MESSAGE_INVALID_EVENT);%0A       %7D%0A       this.start = start;%0A       this.end = end;%0A%0A    
 %7D%0A%09%0A
@@ -753,16 +753,54 @@
 ructor.%0A
+     * @throws IllegalValueException %0A
      */%0A
@@ -837,16 +837,45 @@
  source)
+ throws IllegalValueException
  %7B%0A     
@@ -2117,12 +2117,192 @@
 );%0A    %7D
+%0A    %0A    private static boolean isValidEvent(DateTime start, DateTime end) %7B%0A        if (end.compareTo(start) %3E 0) %7B%0A            return true;%0A        %7D%0A        return false;%0A    %7D
 %0A%0A%7D%0A

Make sure events start time is before end time