package seedu.ezdo.storage;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;

import seedu.ezdo.commons.exceptions.IllegalValueException;
import seedu.ezdo.model.tag.Tag;
import seedu.ezdo.model.tag.UniqueTagList;
import seedu.ezdo.model.todo.DueDate;
import seedu.ezdo.model.todo.Name;
import seedu.ezdo.model.todo.Priority;
import seedu.ezdo.model.todo.ReadOnlyTask;
import seedu.ezdo.model.todo.StartDate;
import seedu.ezdo.model.todo.Task;
import seedu.ezdo.model.todo.TaskDate;

/**
 * JAXB-friendly version of the Task.
 */
public class XmlAdaptedTask {

    @XmlElement(required = true)
    private String name;
    @XmlElement(required = true)
    private String priority;
    @XmlElement(required = true)
    private String email;
    @XmlElement(required = true)
    private String startDate;
    @XmlElement(required = true)
    private String dueDate;
    @XmlElement(required = true)
    private boolean done;
    @XmlElement
    private List<XmlAdaptedTag> tagged = new ArrayList<>();

    /**
     * Constructs an XmlAdaptedTask.
     * This is the no-arg constructor that is required by JAXB.
     */
    public XmlAdaptedTask() {}


    /**
     * Converts a given Task into this class for JAXB use.
     *
     * @param source future changes to this will not affect the created XmlAdaptedTask
     */
    public XmlAdaptedTask(ReadOnlyTask source) {
        name = source.getName().fullName;
        priority = source.getPriority().value;
        startDate = source.getStartDate().value;
        dueDate = source.getDueDate().value;
        done = source.getDone();

        tagged = new ArrayList<>();
        for (Tag tag : source.getTags()) {
            tagged.add(new XmlAdaptedTag(tag));
        }
    }

    /**
     * Converts this jaxb-friendly adapted task object into the model's Task object.
     *
     * @throws IllegalValueException if there were any data constraints violated in the adapted task
     */
    public Task toModelType() throws IllegalValueException {
        final List<Tag> taskTags = new ArrayList<>();
        for (XmlAdaptedTag tag : tagged) {
            taskTags.add(tag.toModelType());
        }
        final Name name = new Name(this.name);
        final Priority priority = new Priority(this.priority);
        final TaskDate startDate = new StartDate(this.startDate);
        final TaskDate dueDate = new DueDate(this.dueDate);
        final UniqueTagList tags = new UniqueTagList(taskTags);
        Task toAdd = new Task(name, priority, startDate, dueDate, tags);
        toAdd.setDone(this.done);
        return toAdd;
    }
}

@@ -407,24 +407,60 @@
 adOnlyTask;%0A
+import seedu.ezdo.model.todo.Recur;%0A
 import seedu
@@ -483,24 +483,24 @@
 .StartDate;%0A
-
 import seedu
@@ -967,32 +967,91 @@
 equired = true)%0A
+    private String recur;%0A    @XmlElement(required = true)%0A
     private bool
@@ -1680,32 +1680,73 @@
 ueDate().value;%0A
+        recur = source.getRecur().value;%0A
         done = s
@@ -2561,24 +2561,75 @@
 s.dueDate);%0A
+        final Recur recur = new Recur(this.recur);%0A
         fina
@@ -2676,24 +2676,24 @@
 (taskTags);%0A
-
         Task
@@ -2745,16 +2745,23 @@
 dueDate,
+ recur,
  tags);%0A

Update XmlAdaptedTask with recur field