package seedu.dailyplanner.storage;

import javax.xml.bind.annotation.XmlElement;

import seedu.dailyplanner.commons.exceptions.IllegalValueException;
import seedu.dailyplanner.model.tag.Tag;
import seedu.dailyplanner.model.tag.UniqueTagList;
import seedu.dailyplanner.model.task.*;

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

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

    @XmlElement(required = true)
    private String name;
    @XmlElement(required = true)
    private String phone;
    @XmlElement(required = true)
    private String email;
    @XmlElement(required = true)
    private String address;
    @XmlElement(required = true)
    private String isCompleted;

    @XmlElement
    private List<XmlAdaptedTag> tagged = new ArrayList<>();

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


    /**
     * Converts a given Person into this class for JAXB use.
     *
     * @param source future changes to this will not affect the created XmlAdaptedPerson
     */
    public XmlAdaptedPerson(ReadOnlyTask source) {
        name = source.getName().fullName;
        phone = source.getPhone().value;
        email = source.getEmail().value;
        address = source.getAddress().value;
        isCompleted = source.getCompletion();
        tagged = new ArrayList<>();
        for (Tag tag : source.getTags()) {
            tagged.add(new XmlAdaptedTag(tag));
        }
    }

    /**
     * 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 List<Tag> personTags = new ArrayList<>();
        for (XmlAdaptedTag tag : tagged) {
            personTags.add(tag.toModelType());
        }
        final Name name = new Name(this.name);
        final Date phone = new Date(this.phone);
        final StartTime email = new StartTime(this.email);
        final EndTime address = new EndTime(this.address);
        final UniqueTagList tags = new UniqueTagList(personTags);
        Task newTask = new Task(name, phone, email, address, tags);
        if (isCompleted.equals("COMPLETE"))
        	newTask.setCompletion(true);
        else
        	newTask.setCompletion(false);
        return newTask;
    }
}

@@ -877,18 +877,22 @@
 rson() %7B
-%7D
 %0A
+    %7D
 %0A%0A    /*
@@ -981,16 +981,34 @@
 m source
+%0A     *           
  future 
@@ -1050,16 +1050,34 @@
  created
+%0A     *           
  XmlAdap
@@ -1145,24 +1145,17 @@
 urce) %7B%0A
-        
+%09
 name = s
@@ -1180,24 +1180,17 @@
 llName;%0A
-        
+%09
 phone = 
@@ -1214,24 +1214,17 @@
 .value;%0A
-        
+%09
 email = 
@@ -1248,24 +1248,17 @@
 .value;%0A
-        
+%09
 address 
@@ -1286,24 +1286,17 @@
 .value;%0A
-        
+%09
 isComple
@@ -1325,24 +1325,17 @@
 tion();%0A
-        
+%09
 tagged =
@@ -1350,32 +1350,25 @@
 ayList%3C%3E();%0A
-        
+%09
 for (Tag tag
@@ -1386,32 +1386,25 @@
 etTags()) %7B%0A
-        
+%09
     tagged.a
@@ -1427,32 +1427,25 @@
 dTag(tag));%0A
-        
+%09
 %7D%0A    %7D%0A%0A   
@@ -1525,24 +1525,31 @@
 del's Person
+%0A     *
  object.%0A   
@@ -1588,16 +1588,35 @@
 xception
+%0A     *            
  if ther
@@ -1662,24 +1662,43 @@
  the adapted
+%0A     *            
  person%0A    
@@ -1762,24 +1762,17 @@
 ption %7B%0A
-        
+%09
 final Li
@@ -1811,24 +1811,17 @@
 st%3C%3E();%0A
-        
+%09
 for (Xml
@@ -1847,24 +1847,17 @@
 gged) %7B%0A
-        
+%09
     pers
@@ -1891,26 +1891,12 @@
 ));%0A
-        %7D%0A        
+%09%7D%0A%09
 fina
@@ -1926,32 +1926,25 @@
 this.name);%0A
-        
+%09
 final Date p
@@ -1972,24 +1972,17 @@
 phone);%0A
-        
+%09
 final St
@@ -2024,24 +2024,17 @@
 email);%0A
-        
+%09
 final En
@@ -2076,24 +2076,17 @@
 dress);%0A
-        
+%09
 final Un
@@ -2135,24 +2135,17 @@
 nTags);%0A
-        
+%09
 Task new
@@ -2196,24 +2196,17 @@
  tags);%0A
-        
+%09
 if (isCo
@@ -2233,25 +2233,21 @@
 LETE%22))%0A
-    
+%09
     
-%09
 newTask.
@@ -2271,30 +2271,19 @@
 e);%0A
-        
+%09
 else%0A
- 
+%09
     
-   %09
 newT
@@ -2308,24 +2308,17 @@
 false);%0A
-        
+%09
 return n

Refactor XmlAdaptedPerson