package seedu.taskitty.model.task;

import seedu.taskitty.commons.exceptions.IllegalValueException;
import seedu.taskitty.commons.util.CollectionUtil;
import seedu.taskitty.model.tag.UniqueTagList;

import java.util.Objects;

/**
 * Represents a Task in the address book.
 * Guarantees: details are present and not null, field values are validated.
 */
public class Task implements ReadOnlyTask {
    
    public static final int TASK_COMPONENT_INDEX_NAME = 0;
    public static final int TASK_COMPONENT_COUNT = 1;
    
    public static final int DEADLINE_COMPONENT_INDEX_NAME = 0;
    public static final int DEADLINE_COMPONENT_INDEX_END_DATE = 1;
    public static final int DEADLINE_COMPONENT_INDEX_END_TIME = 2;
    public static final int DEADLINE_COMPONENT_COUNT = 3;
    
    public static final int EVENT_COMPONENT_INDEX_NAME = 0;
    public static final int EVENT_COMPONENT_INDEX_START_DATE = 1;
    public static final int EVENT_COMPONENT_INDEX_START_TIME = 2;
    public static final int EVENT_COMPONENT_INDEX_END_DATE = 3;
    public static final int EVENT_COMPONENT_INDEX_END_TIME = 4;
    public static final int EVENT_COMPONENT_COUNT = 5;

    private Name name;
    private TaskDate startDate;
    private TaskTime startTime;
    private TaskDate endDate;
    private TaskTime endTime;
    private boolean isDone;

    private UniqueTagList tags;

    /**
     * Every field must be present and not null.
     */
    public Task(Name name, TaskDate startDate, TaskTime startTime,
            TaskDate endDate, TaskTime endTime, UniqueTagList tags) {
        assert !CollectionUtil.isAnyNull(name, tags);
        
        this.name = name;
        this.startDate = startDate;
        this.startTime = startTime;
        this.endDate = startDate;
        this.endTime = endTime;
        this.tags = new UniqueTagList(tags); // protect internal tags from changes in the arg list
    }

    /**
     * Copy constructor.
     */
    public Task(ReadOnlyTask source) {
        this(source.getName(), source.getStartDate(), source.getStartTime(),
                source.getEndDate(), source.getEndTime(), source.getTags());
    }

    @Override
    public Name getName() {
        return name;
    }
    
    @Override
    public TaskDate getStartDate() {
        return startDate;
    }
    
    @Override
    public TaskDate getEndDate() {
        return endDate;
    }

    @Override
    public TaskTime getStartTime() {
        return startTime;
    }

    @Override
    public TaskTime getEndTime() {
        return endTime;
    }

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

    /**
     * Replaces this person's tags with the tags in the argument tag list.
     */
    public void setTags(UniqueTagList replacement) {
        tags.setTags(replacement);
    }
    
    /** 
     * Marks task as done.
     */
    public void markAsDone() {
    	if (!isDone) {
    		this.isDone = true;
    		try {
    			this.name = new Name(this.name + " DONE");
    		} catch (IllegalValueException e) {
    			e.printStackTrace();
    		}
    	}
    }

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

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

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

	@Override
	public boolean getIsDone() {
		return isDone;
	}
}

@@ -1362,24 +1362,993 @@
 s;%0A%0A    /**%0A
+     * Constructor for a %22todo%22 Task.%0A     * %22todo%22 is a Task only has name%0A     * Every field must be present and not null.%0A     */%0A    public Task(Name name, UniqueTagList tags) %7B%0A        System.out.println(%22TODO%22);%0A        assert !CollectionUtil.isAnyNull(name, tags);%0A        %0A        this.name = name;%0A        this.tags = new UniqueTagList(tags);%0A    %7D%0A    %0A    /**%0A     * Constructor for a %22deadline%22 Task.%0A     * %22deadline%22 is a Task only has name, endDate and endTime%0A     * Every field must be present and not null.%0A     */%0A    public Task(Name name, TaskDate endDate, TaskTime endTime, UniqueTagList tags) %7B%0A        System.out.println(%22DEADLINE%22);%0A        assert !CollectionUtil.isAnyNull(name, endDate, endTime, tags);%0A        %0A        this.name = name;%0A        this.endDate = endDate;%0A        this.endTime = endTime;%0A        this.tags = new UniqueTagList(tags);%0A    %7D%0A    %0A    /**%0A     * Constructor for a %22event%22 Task.%0A     * %22event%22 is a Task all fields.%0A
      * Every
@@ -2376,32 +2376,32 @@
 t and not null.%0A
-
      */%0A    publ
@@ -2521,32 +2521,69 @@
 TagList tags) %7B%0A
+        System.out.println(%22EVENT%22);%0A
         assert !
@@ -2604,32 +2604,72 @@
 .isAnyNull(name,
+ startDate, startTime, endDate, endTime,
  tags);%0A        

Split constructor into 3 types