package seedu.jimi.storage;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import seedu.jimi.commons.exceptions.IllegalValueException;
import seedu.jimi.model.ReadOnlyTaskBook;
import seedu.jimi.model.event.Event;
import seedu.jimi.model.tag.Tag;
import seedu.jimi.model.tag.UniqueTagList;
import seedu.jimi.model.task.DeadlineTask;
import seedu.jimi.model.task.FloatingTask;
import seedu.jimi.model.task.ReadOnlyTask;
import seedu.jimi.model.task.UniqueTaskList;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * An Immutable TaskBook that is serializable to XML format
 */
@XmlRootElement(name = "jimi")
public class XmlSerializableTaskBook implements ReadOnlyTaskBook {

    @XmlElement
    private List<XmlAdaptedTask> tasks;

    @XmlElement
    private List<Tag> tags;

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

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

    /**
     * Conversion
     */
    public XmlSerializableTaskBook(ReadOnlyTaskBook src) {
        tasks.addAll(src.getTaskList().stream().map(XmlAdaptedTask::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 UniqueTaskList getUniqueTaskList() {
        UniqueTaskList lists = new UniqueTaskList();
        for (XmlAdaptedTask p : tasks) {
            try {
                lists.add(p.toModelType());
            } catch (IllegalValueException e) {
                //TODO: better error handling
            }
        }
        return lists;
    }

    @Override
    public List<ReadOnlyTask> getTaskList() {
        return tasks.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);
    }

}

@@ -22,16 +22,134 @@
 orage;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.stream.Collectors;%0A%0A
 import j
@@ -341,45 +341,8 @@
 ok;%0A
-import seedu.jimi.model.event.Event;%0A
 impo
@@ -446,269 +446,65 @@
 ask.
-DeadlineTask;%0Aimport seedu.jimi.model.task.FloatingTask;%0Aimport seedu.jimi.model.task.ReadOnlyTask;%0Aimport seedu.jimi.model.task.UniqueTaskList;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.stream.Collectors
+ReadOnlyTask;%0Aimport seedu.jimi.model.task.UniqueTaskList
 ;%0A%0A/
@@ -1525,24 +1525,38 @@
 iqueTaskList
+%3CReadOnlyTask%3E
  getUniqueTa
@@ -1588,16 +1588,30 @@
 TaskList
+%3CReadOnlyTask%3E
  lists =
@@ -1625,24 +1625,38 @@
 iqueTaskList
+%3CReadOnlyTask%3E
 ();%0A        

Remove unused imports + add type