package seedu.address.model.task;

import java.util.Objects;
import java.util.Optional;

import seedu.address.commons.util.CollectionUtil;
import seedu.address.model.tag.UniqueTagList;

/**
 * Represents a Task in the address book.
 * Guarantees: details are present and not null, field values are validated.
 */
public class Task implements ReadOnlyTask {

    private Name name;

    private UniqueTagList tags;

    private Optional<StartEndDateTime> startEndDateTime;

    private Optional<Deadline> deadline;

    /**
     * Every field must be present and not null. // TODO
     * @param startEndDateTime
     * @param deadline
     */
    public Task(Name name, Optional<Deadline> deadline, Optional<StartEndDateTime> startEndDateTime,
            UniqueTagList tags) {
        assert !CollectionUtil.isAnyNull(name, deadline, startEndDateTime, tags);
        this.name = name;
        this.deadline = deadline;
        this.startEndDateTime = startEndDateTime;
        this.tags = new UniqueTagList(tags); // protect internal tags from changes in the arg list
    }

    /**
     * Creates a copy of the given ReadOnlyTask.
     */
    public Task(ReadOnlyTask source) {
        this(source.getName(), source.getDeadline(), source.getStartEndDateTime(), source.getTags());
    }

    public void setName(Name name) {
        assert name != null;
        this.name = name;
    }

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


    @Override
    public Optional<StartEndDateTime> getStartEndDateTime() {
        return startEndDateTime;
    }

    /**
     * TODO Only accepts a StartEndDateTime if not there is no point updating the value
     */
    public void setStartEndDateTime(StartEndDateTime dateTime) {
        assert dateTime != null;
        this.startEndDateTime = Optional.of(dateTime);
    }

    @Override
    public Optional<Deadline> getDeadline() {
        return deadline;
    }

    public void setDeadline(Deadline dateTime) {
        assert dateTime != null;
        this.deadline = Optional.of(dateTime);
    }

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

    /**
     * Replaces this task's tags with the tags in the argument tag list.
     */
    public void setTags(UniqueTagList replacement) {
        tags.setTags(replacement);
    }

    /**
     * Updates this task with the details of {@code replacement}.
     */
    public void resetData(ReadOnlyTask replacement) {
        assert replacement != null;

        this.setName(replacement.getName());
        this.setTags(replacement.getTags());
    }

    @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();
    }

}

@@ -215,20 +215,17 @@
 the 
-address book
+task list
 .%0A *
@@ -541,94 +541,59 @@
 ust 
-be present and not null. // TODO%0A     * @param startEndDateTime%0A     * @param deadline
+not be null except for the %7B@code Optional%7D fields.
 %0A   
@@ -1412,17 +1412,16 @@
 %0A    %7D%0A%0A
-%0A
     @Ove
@@ -1450,44 +1450,28 @@
 nal%3C
-StartEndDateTime%3E getStartEndDateTim
+Deadline%3E getDeadlin
 e() 
@@ -1487,31 +1487,23 @@
  return 
-startEndDateTim
+deadlin
 e;%0A    %7D
@@ -1522,28 +1522,39 @@
    *
- TODO
  Only a
-ccepts a
+llow changing the %7B@link
  Sta
@@ -1570,16 +1570,13 @@
 Time
+%7D
  if 
-not 
 ther
@@ -1584,95 +1584,92 @@
  is 
-no point updating the value%0A     */%0A    public void setStartEndDateTime(StartEndDateTim
+actually a value (not %7B@link Optional%7D).%0A     */%0A    public void setDeadline(Deadlin
 e da
@@ -1720,39 +1720,31 @@
        this.
-startEndDateTim
+deadlin
 e = Optional
@@ -1803,101 +1803,266 @@
 nal%3C
-Deadline%3E getDeadline() %7B%0A        return deadline;%0A    %7D%0A%0A    public void setDeadline(Deadlin
+StartEndDateTime%3E getStartEndDateTime() %7B%0A        return startEndDateTime;%0A    %7D%0A%0A    /**%0A     * Only allow changing the %7B@link StartEndDateTime%7D if there is actually a value (not %7B@link Optional%7D).%0A     */%0A    public void setStartEndDateTime(StartEndDateTim
 e da
@@ -2109,39 +2109,47 @@
 l;%0A        this.
-deadlin
+startEndDateTim
 e = Optional.of(
@@ -2662,24 +2662,714 @@
 getName());%0A
+        // TODO to use or not to use a new Optional to wrap the Deadline%0A        // replacement Deadline is currently reused%0A        if (replacement.getDeadline().isPresent()) %7B%0A            this.deadline = Optional.of(replacement.getDeadline().get());%0A        %7D else %7B%0A            this.deadline = Optional.empty();%0A        %7D%0A        // TODO to use or not to use a new Optional to wrap the startEndDateTime%0A        // replacement startEndDateTime is currently reused%0A        if (replacement.getStartEndDateTime().isPresent()) %7B%0A            this.startEndDateTime = Optional.of(replacement.getStartEndDateTime().get());%0A        %7D else %7B%0A            this.deadline = Optional.empty();%0A        %7D%0A
         this

Clean up Task