package seedu.taskman.model.event;

import seedu.taskman.model.tag.UniqueTagList;

import java.util.Optional;

/**
 * Wrapper for both ReadOnlyEvent and ReadOnlyTask
 */
public class Activity implements ReadOnlyEvent{

    public enum ActivityType {EVENT, TASK};

    private ReadOnlyEvent activity;
    private ActivityType type;

    public Activity(ReadOnlyEvent event){
        activity = event;
        type = ActivityType.EVENT;
    }

    public Activity(ReadOnlyTask task){
        activity = task;
        type = ActivityType.TASK;
    }

    public ActivityType getType(){
        return type;
    }

    public Optional<Status> getStatus() {
        switch(type){
            case TASK:
                return Optional.ofNullable(((ReadOnlyTask)activity).getStatus());
            case EVENT:
            default:
                return null;
        }
    }

    public Optional<Deadline> getDeadline() {
        switch(type){
            case TASK:
                return ((ReadOnlyTask)activity).getDeadline();
            case EVENT:
            default:
                return Optional.empty();
        }
    }

    @Override
    public Title getTitle() {
        return activity.getTitle();
    }

    @Override
    public Optional<Frequency> getFrequency() {
        return activity.getFrequency();
    }

    @Override
    public Optional<Schedule> getSchedule() {
        return activity.getSchedule();
    }

    @Override
    public UniqueTagList getTags() {
        return activity.getTags();
    }

    @Override
    public boolean isSameStateAs(ReadOnlyEvent other) {
        return other.isSameStateAs(activity);
    }

    @Override
    public String getAsText() {
        return activity.getAsText();
    }

}

@@ -72,24 +72,50 @@
 ueTagList;%0A%0A
+import java.util.Objects;%0A
 import java.
@@ -622,32 +622,225 @@
 rn type;%0A    %7D%0A%0A
+    public ReadOnlyTask getTask()%7B%0A        assert type == ActivityType.TASK;%0A        return (ReadOnlyTask) activity;%0A    %7D%0A%0A    public ReadOnlyEvent getEvent()%7B%0A        return activity;%0A    %7D%0A%0A
     public Optio
@@ -1743,71 +1743,388 @@
     
-@Override%0A    public boolean isSameStateAs(ReadOnlyEven
+public boolean isSameStateAs(Activity other)%7B%0A        if(type != other.type) return false;%0A%0A        switch(type)%7B%0A            case TASK:%0A                return getTask().isSameStateAs(other.getTask());%0A            case EVENT:%0A            default:%0A                return activity.isSameStateAs(other.activity);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public boolean equals(Objec
 t other)
  %7B%0A 
@@ -2119,17 +2119,16 @@
 t other)
- 
 %7B%0A      
@@ -2145,31 +2145,530 @@
 ther
-.isSameStateAs(activity
+ == this // short circuit if same object%0A                %7C%7C (other instanceof Activity // instanceof handles nulls%0A                && this.isSameStateAs((Activity) other));%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        // use this method for custom fields hashing instead of implementing your own%0A        return Objects.hash(%0A                getTitle(),%0A                getDeadline(),%0A                getStatus(),%0A                getFrequency(),%0A                getSchedule(),%0A                getTags()%0A        
 );%0A 

Implement ReadOnlyTask and ReadOnlyEvent getters, isSameStateAs, equals and hashCode for Activity