package seedu.address.storage;

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

import javax.xml.bind.annotation.XmlElement;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.tag.Tag;
import seedu.address.model.tag.UniqueTagList;
import seedu.address.model.task.Deadline;
import seedu.address.model.task.Description;
import seedu.address.model.task.IdentificationNumber;
import seedu.address.model.task.Name;
import seedu.address.model.task.ReadOnlyTask;
import seedu.address.model.task.Task;

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

    @XmlElement(required = true)
    private String name;
    @XmlElement(required = true)
    private String deadline;
    @XmlElement(required = true)
    private String description;
    @XmlElement(required = true)
    private String id;

    @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().name;
        deadline = source.getDeadline().date.toString();
        description = source.getDescription().description;
        id = Integer.toString(source.getID().value);
        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 Deadline phone = new Deadline(this.deadline);
        final Description email = new Description(this.description);
        final IdentificationNumber address = new IdentificationNumber(this.id);
        final UniqueTagList tags = new UniqueTagList(taskTags);
        return new Task(name, phone, email, address, tags);
    }
}

@@ -1328,20 +1328,26 @@
 tName().
-name
+toString()
 ;%0A      
@@ -1384,13 +1384,8 @@
 e().
-date.
 toSt
@@ -1438,27 +1438,26 @@
 ption().
-description
+toString()
 ;%0A      
@@ -1467,25 +1467,8 @@
 d = 
-Integer.toString(
 sour
@@ -1482,13 +1482,17 @@
 D().
-value
+toString(
 );%0A 

Modify methods called