package seedu.address.storage;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.tag.Tag;
import seedu.address.model.tag.UniqueTagList;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.ReadOnlyTask;
import seedu.address.model.person.UniquePersonList;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * An Immutable AddressBook that is serializable to XML format
 */
@XmlRootElement(name = "addressbook")
public class XmlSerializableAddressBook implements ReadOnlyAddressBook {

    @XmlElement
    private List<XmlAdaptedPerson> persons;
    @XmlElement
    private List<Tag> tags;

    {
        persons = new ArrayList<>();
        tags = new ArrayList<>();
    }

    /**
     * Empty constructor required for marshalling
     */
    public XmlSerializableAddressBook() {}

    /**
     * Conversion
     */
    public XmlSerializableAddressBook(ReadOnlyAddressBook src) {
        persons.addAll(src.getPersonList().stream().map(XmlAdaptedPerson::new).collect(Collectors.toList()));
        tags = src.getTagList();
    }

    @Override
    public UniqueTagList getUniqueTagList() {
        try {
            return new UniqueTagList(tags);
        } catch (UniqueTagList.DuplicateTagException e) {
            //TODO: better error handling
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public UniquePersonList getUniquePersonList() {
        UniquePersonList lists = new UniquePersonList();
        for (XmlAdaptedPerson p : persons) {
            try {
                lists.add(p.toModelType());
            } catch (IllegalValueException e) {
                //TODO: better error handling
            }
        }
        return lists;
    }

    @Override
    public List<ReadOnlyTask> getPersonList() {
        return persons.stream().map(p -> {
            try {
                return p.toModelType();
            } catch (IllegalValueException e) {
                e.printStackTrace();
                //TODO: better error handling
                return null;
            }
        }).collect(Collectors.toCollection(ArrayList::new));
    }

    @Override
    public List<Tag> getTagList() {
        return Collections.unmodifiableList(tags);
    }

    @Override
    public UniquePersonList getUniqueUndatedTaskList() {
        UniquePersonList lists = new UniquePersonList();
        for (XmlAdaptedPerson p : persons) {
            try {
                lists.add(p.toModelType());
            } catch (IllegalValueException e) {

            }
        }
        return lists;
    }

    @Override
    public List<ReadOnlyTask> getUndatedTaskList() {
        return persons.stream().map(p -> {
            try {
                return p.toModelType();
            } catch (IllegalValueException e) {
                e.printStackTrace();
                return null;
            }
        }).collect(Collectors.toCollection(ArrayList::new));
    }

}

@@ -811,40 +811,147 @@
 ist%3C
-Tag%3E tags;%0A%0A    %7B%0A        person
+XmlAdaptedPerson%3E undatedTasks;%0A    @XmlElement%0A    private List%3CTag%3E tags;%0A%0A    %7B%0A        persons = new ArrayList%3C%3E();%0A        undatedTask
 s = 
@@ -1325,24 +1325,144 @@
 toList()));%0A
+        undatedTasks.addAll(src.getUndatedTaskList().stream().map(XmlAdaptedPerson::new).collect(Collectors.toList()));%0A
         tags
@@ -2826,38 +2826,43 @@
 aptedPerson p : 
-person
+undatedTask
 s) %7B%0A           
@@ -3088,38 +3088,43 @@
 %0A        return 
-person
+undatedTask
 s.stream().map(p

Add undatedTasks element in XmlSerializableAddressBook.java