package seedu.address.model.task;

import seedu.address.commons.util.CollectionUtil;
import seedu.address.model.tag.UniqueTagList;

import java.util.Objects;

import javafx.beans.Observable;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.util.Callback;

/**
 * Represents an event or a task (with or without deadline) in the task manager.
 * Guarantees: details are present and not null, field values are validated.
 */
public class Task implements ReadOnlyTask {

    private boolean isEvent;
    private Name name;
    private Date date;
    private boolean isDone;
    private BooleanProperty done; // Use Observable so that listeners can know when the task's done status is updated

    private UniqueTagList tags;

    /**
     * Every field must be present and not null.
     */
    public Task(Name name, Date date, UniqueTagList tags) {
        this(name, date, tags, false);
    }
    
    public Task(Name name, Date date, UniqueTagList tags, boolean isDone) {
        assert !CollectionUtil.isAnyNull(name, date, tags);
        this.name = name;
        this.date = date;
        if (date instanceof EventDate) {
            isEvent = true;
        } else {
            isEvent = false;
        }
        this.tags = new UniqueTagList(tags); // protect internal tags from changes in the arg list
        this.isDone = isDone;
        this.done = new SimpleBooleanProperty(isDone);
    }

    /**
     * Copy constructor.
     */
    public Task(ReadOnlyTask source) {
        this(source.getName(), source.getDate(), source.getTags(), source.isDone());
    }
    
    public Task(Name name) {
    	this.name=name;
	}

	@Override
    public Name getName() {
        return name;
    }

    @Override
    public Date getDate() {
        return date;
    }
    
    @Override
    public boolean isEvent() {
        return isEvent;
    }
    
    @Override
    public boolean isDone(){
    	return isDone;
    }
    
    /**
     * Returns the Observable wrapper of the done status
     */
    public BooleanProperty getDone() {
        return done;
    }
    
    @Override
    public UniqueTagList getTags() {
        return new UniqueTagList(tags);
    }

    /**
     * Replaces this task's tags with the tags in the argument tag list.
     */
    public void setTags(UniqueTagList replacement) {
        tags.setTags(replacement);
    }

    @Override
    public boolean equals(Object other) {
        return other == this // short circuit if same object
                || (other instanceof ReadOnlyTask // instanceof handles nulls
                && this.isSameStateAs((ReadOnlyTask) other));
    }

    @Override
    public int hashCode() {
        // use this method for custom fields hashing instead of implementing your own
        return Objects.hash(name, date, tags, isDone);
    }

    @Override
    public String toString() {
        return getAsText();
    }

	@Override
	public void markAsDone() {
		isDone=true;
		done.set(true);
	}
	
	/*
	 * Makes Task observable by its done status
	 */
	public static Callback<Task, Observable[]> extractor() {
	    return (Task task) -> new Observable[]{task.getDone()};
	}

}

@@ -704,16 +704,53 @@
 can know
+%0A                                  //
  when th
@@ -977,36 +977,32 @@
 , false);%0A    %7D%0A
-    
 %0A    public Task
@@ -1373,16 +1373,64 @@
 ags from
+%0A                                             //
  changes
@@ -1705,28 +1705,24 @@
 e());%0A    %7D%0A
-    
 %0A    public 
@@ -1743,17 +1743,20 @@
 ) %7B%0A    
-%09
+    
 this.nam
@@ -1760,20 +1760,28 @@
 name
-=
+ = 
 name;%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 @Ove
@@ -1903,36 +1903,32 @@
 urn date;%0A    %7D%0A
-    
 %0A    @Override%0A 
@@ -1979,36 +1979,32 @@
  isEvent;%0A    %7D%0A
-    
 %0A    @Override%0A 
@@ -2033,15 +2033,19 @@
 ne()
+ 
 %7B%0A    
-%09
+    
 retu
@@ -2057,28 +2057,24 @@
 Done;%0A    %7D%0A
-    
 %0A    /**%0A   
@@ -2201,20 +2201,16 @@
 ;%0A    %7D%0A
-    
 %0A    @Ov
@@ -2695,16 +2695,24 @@
         
+        
 && this.
@@ -2874,16 +2874,27 @@
 ementing
+%0A        //
  your ow
@@ -3037,17 +3037,20 @@
 %0A    %7D%0A%0A
-%09
+    
 @Overrid
@@ -3051,17 +3051,20 @@
 verride%0A
-%09
+    
 public v
@@ -3086,25 +3086,39 @@
 ) %7B%0A
-%09%09
+        
 isDone
-=
+ = 
 true;%0A
-%09%09
+        
 done
@@ -3133,18 +3133,26 @@
 e);%0A
-%09%7D%0A%09%0A%09/*%0A%09
+    %7D%0A%0A    /*%0A    
  * M
@@ -3195,14 +3195,20 @@
 tus%0A
-%09 */%0A%09
+     */%0A    
 publ
@@ -3264,13 +3264,16 @@
 ) %7B%0A
-%09
+ 
     
+   
 retu
@@ -3306,17 +3306,19 @@
 rvable%5B%5D
-%7B
+ %7B 
 task.get
@@ -3327,12 +3327,16 @@
 ne()
+ 
 %7D;%0A
-%09
+    
 %7D%0A%0A%7D

refactor Task class