//@@author A0138474X
package seedu.address.storage;

import javax.xml.bind.annotation.XmlElement;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.tag.Tag;
import seedu.address.model.task.Description;
import seedu.address.model.task.Name;
import seedu.address.model.task.Priority;
import seedu.address.model.task.ReadOnlyTask;
import seedu.address.model.task.Task;
import seedu.address.model.task.TaskDate;
import seedu.address.model.task.TaskTime;
import seedu.address.model.task.Venue;

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

    @XmlElement(required = true)
    private String name;
    @XmlElement(required = false)
    private String date;
    @XmlElement(required = false)
    private String time;
    @XmlElement(required = false)
    private String tag;
    @XmlElement(required = false)
    private String description;
    @XmlElement(required = false)
    private String venue;
    @XmlElement(required = false)
    private String priority;
    @XmlElement(required = false)
    private boolean isFavourite;
    @XmlElement(required = false)
    private boolean isFinished;

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


    /**
     * Converts a given Person into this class for JAXB use.
     *
     * @param source future changes to this will not affect the created XmlAdaptedPerson
     */
    public XmlAdaptedTask(ReadOnlyTask source) {
        name = source.getName().fullName;
        date = source.getDate().getValue();
        time = source.getTime().getValue();
        tag = source.getTag().tagName;
        description = source.getDescription().getValue();
        venue = source.getVenue().getValue();
        priority = source.getPriority().getValue();
        isFavourite = source.isFavorite();
        isFinished = source.isFinished();
    }

    /**
     * Converts this jaxb-friendly adapted person object into the model's Person object.
     *
     * @throws IllegalValueException if there were any data constraints violated in the adapted person
     */
    public Task toModelType() throws IllegalValueException {
        final Name name = new Name(this.name);
        final TaskDate date = new TaskDate(this.date);
        final TaskTime time = new TaskTime(this.time);
        final Description description = new Description(this.description);
        final Tag tag = new Tag(this.tag);
        final Venue venue = new Venue(this.venue);
        final Priority priority = new Priority(this.priority);
        return new Task(name, date, time, description, tag, venue, priority, isFavourite, isFinished);
    }

    public String getTagName() {
        return this.tag;
    }
}

@@ -232,24 +232,63 @@
 escription;%0A
+import seedu.address.model.task.Event;%0A
 import seedu
@@ -355,16 +355,63 @@
 iority;%0A
+import seedu.address.model.task.ReadOnlyEvent;%0A
 import s
@@ -720,37 +720,39 @@
 d = true)%0A    pr
-ivate
+otected
  String name;%0A  
@@ -781,37 +781,39 @@
  = false)%0A    pr
-ivate
+otected
  String date;%0A  
@@ -842,37 +842,39 @@
  = false)%0A    pr
-ivate
+otected
  String time;%0A  
@@ -903,37 +903,39 @@
  = false)%0A    pr
-ivate
+otected
  String tag;%0A   
@@ -963,37 +963,39 @@
  = false)%0A    pr
-ivate
+otected
  String descript
@@ -1031,37 +1031,39 @@
  = false)%0A    pr
-ivate
+otected
  String venue;%0A 
@@ -1101,21 +1101,23 @@
 )%0A    pr
-ivate
+otected
  String 
@@ -1126,16 +1126,215 @@
 iority;%0A
+    @XmlElement(required = true)%0A    protected boolean isFavourite;%0A    @XmlElement(required = true)%0A    protected boolean isFinished;%0A    @XmlElement(required = true)%0A    protected boolean isEvent;%0A
     @Xml
@@ -1371,33 +1371,30 @@
 private 
-boolean isFavouri
+String startDa
 te;%0A    
@@ -1435,34 +1435,32 @@
 private 
-boolean isFinished
+String startTime
 ;%0A%0A    /
@@ -2234,24 +2234,241 @@
 Finished();%0A
+        isEvent = source.isEvent();%0A        if(isEvent)%7B%0A            startDate = ((ReadOnlyEvent)source).getStartDate().getValue();%0A            startTime = ((ReadOnlyEvent)source).getStartTime().getValue();%0A        %7D%0A
     %7D%0A%0A    /
@@ -3127,16 +3127,395 @@
 ority);%0A
+        if(isEvent)%7B%0A            final TaskDate startDate = new TaskDate(this.startDate);%0A            final TaskTime startTime = new TaskTime(this.startTime);%0A            Event event = new Event(name, startDate, startTime,date, time, description, tag, venue, priority, %0A                    isFavourite, isFinished, isEvent);%0A            return event;%0A        %7D%0A        else%7B%0A    
         
@@ -3606,18 +3606,37 @@
 Finished
-);
+, isEvent);%0A        %7D
 %0A    %7D%0A%0A

edit XmlAdaptedTask to store and load event