package tars.storage;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.xml.bind.annotation.XmlElement;

import tars.commons.exceptions.IllegalValueException;
import tars.model.task.DateTime;
import tars.model.task.Name;
import tars.model.task.Priority;
import tars.model.task.rsv.RsvTask;

/**
 * JAXB-friendly version of the RsvTask.
 */
public class XmlAdaptedRsvTask {

    @XmlElement(required = true)
    private String name;
    @XmlElement
    private String priority;

    @XmlElement
    private List<DateTime> reservedDateTime;

    @XmlElement
    private List<String> tempTags;

    /**
     * No-arg constructor for JAXB use.
     */
    public XmlAdaptedRsvTask() {
    }

    /**
     * Converts a given Reserved Task into this class for JAXB use.
     *
     * @param source
     *            future changes to this will not affect the created
     *            XmlAdaptedRsvTask
     */
    public XmlAdaptedRsvTask(RsvTask source) {
        name = source.getName().taskName;
        priority = source.getPriority().priorityLevel;
        reservedDateTime = new ArrayList<>();
        for (DateTime dt : source.getDateTimeSet()) {
            reservedDateTime.add(dt);
        }
        tempTags = new ArrayList<>();
        for (String tag : source.getTempTagSet()) {
            tempTags.add(tag);
        }
    }

    /**
     * Converts this jaxb-friendly adapted task object into the model's RsvTask
     * object.
     *
     * @throws IllegalValueException
     *             if there were any data constraints violated in the adapted
     *             rsvTask
     */
    public RsvTask toModelType() throws IllegalValueException {

        Set<DateTime> dateTimeSet = new HashSet<>();
        for (DateTime dt : this.reservedDateTime) {
            dateTimeSet.add(new DateTime(dt.startDateString, dt.endDateString));
        }

        Set<String> tempTagSet = new HashSet<>();
        if (tempTags != null) {
            for (String tag : this.tempTags) {
                tempTagSet.add(tag);
            }
        }

        final Name name = new Name(this.name);
        final Priority priority = new Priority(this.priority);

        return new RsvTask(name, dateTimeSet, priority, tempTagSet);
    }

}


@@ -492,53 +492,8 @@
 ame;
-%0A    @XmlElement%0A    private String priority;
 %0A%0A  
@@ -556,60 +556,8 @@
 e;%0A%0A
-    @XmlElement%0A    private List%3CString%3E tempTags;%0A%0A
     
@@ -958,63 +958,8 @@
 me;%0A
-        priority = source.getPriority().priorityLevel;%0A
     
@@ -1106,139 +1106,8 @@
   %7D%0A
-        tempTags = new ArrayList%3C%3E();%0A        for (String tag : source.getTempTagSet()) %7B%0A            tempTags.add(tag);%0A        %7D%0A
     
@@ -1630,25 +1630,24 @@
       %7D%0A
-%0A
         
 Set%3CStri
@@ -1642,298 +1642,53 @@
     
-Set%3CString%3E tempTagSet = new HashSet%3C%3E();%0A        if (tempTags != null) %7B%0A            for (String tag : this.tempTags) %7B%0A                tempTagSet.add(tag);%0A            %7D%0A        %7D%0A%0A        final Name name = new Name(this.name);%0A        final Priority priority = new Priority(this.priority
+%0A        final Name name = new Name(this.name
 );%0A%0A
@@ -1735,30 +1735,8 @@
 eSet
-, priority, tempTagSet
 );%0A 

Remove prioirty and dateTime attributes