package com.example.habitrack;

import java.util.ArrayList;
import java.util.Calendar;

import io.searchbox.annotations.JestId;

/**
 *
 * HabitType
 *
 * Version 1.01
 *
 * Created by sshussai on 10/21/17.
 *
 */

public class HabitType {
    /**
     * This class is the template for a habit type entity.
     *
     */

    private final Integer ID;
    private String title;                   // title of the habit type
    private String reason;                  // reason for the habit type
    private Calendar startDate;             // Calendar object representing the start date
    private ArrayList<Integer> schedule;    // ArrayList of ints representing days of the week for the plan
    private Integer completedCounter;       // habit events currently completed
    private Integer currentMaxCounter;      // total number of habits events possible so far
    @JestId
    private String id;                      // Elastic Search ID for the habit

    public HabitType(Integer id) {
        this.ID = id;
        this.completedCounter = 0;
        this.currentMaxCounter = 0;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public Calendar getStartDate() {
        return startDate;
    }

    public void setStartDate(Calendar startDate) {
        this.startDate = startDate;
    }

    public ArrayList<Integer> getSchedule() {
        return schedule;
    }

    public void setSchedule(ArrayList<Integer> plan) {
        this.schedule = plan;
    }

    public Double getStatus(){
        return (completedCounter.doubleValue()/currentMaxCounter.doubleValue());}

    public Integer getID() {
        return ID;
    }

    public Integer getCompletedCounter() {
        return completedCounter;
    }

    public Integer getCurrentMaxCounter() {
        return currentMaxCounter;
    }

    public String getElasticSearchId() {
        return id;
    }

    public void incrementCompletedCounter(){
        completedCounter++;
    }

    public void incrementMaxCounter(){
        currentMaxCounter++;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public String toString(){return getID().toString() + " | " + getTitle();}
}

@@ -862,16 +862,357 @@
  so far%0A
+    private Boolean canBeScheduled;         // Boolean variable that determines if events can be scheduled%0A    private String userID;                  // userID of the current user%0A    private HabitTypeMetadata myData;       // Metadata object for the current habit type%0A    private HabitEvent mostRecentEvent;     // Most recent habitEvent%0A
     @Jes
@@ -1215,16 +1215,16 @@
 @JestId%0A
-
     priv
@@ -1419,24 +1419,192 @@
 ounter = 0;%0A
+        this.canBeScheduled = Boolean.FALSE;%0A        this.myData = new HabitTypeMetadata(this.ID, this.id);%0A        this.myData.setCanBeScheduled(this.canBeScheduled);%0A
     %7D%0A%0A    p
@@ -1719,32 +1719,74 @@
 .title = title;%0A
+        this.myData.setTitle(this.title);%0A
     %7D%0A%0A    publi
@@ -2035,24 +2035,25 @@
 tartDate) %7B%0A
+%0A
         this
@@ -2068,32 +2068,744 @@
 te = startDate;%0A
+        // Check if ht can be scheduled ONLY if start date is BEFORE OR EQUAL today%0A        Calendar today = Calendar.getInstance();%0A        if(startDate.get(Calendar.YEAR) %3C today.get(Calendar.YEAR)%0A                %7C%7C (startDate.get(Calendar.YEAR) %3C= today.get(Calendar.YEAR)%0A                && startDate.get(Calendar.MONTH) %3C today.get(Calendar.MONTH))%0A                %7C%7C (startDate.get(Calendar.MONTH) %3C= today.get(Calendar.MONTH)%0A                && startDate.get(Calendar.YEAR) %3C= today.get(Calendar.YEAR)%0A                && startDate.get(Calendar.DATE) %3C= today.get(Calendar.DATE))) %7B%0A            this.canBeScheduled = Boolean.TRUE;%0A            this.myData.setCanBeScheduled(this.canBeScheduled);%0A        %7D%0A
     %7D%0A%0A    publi
@@ -2958,16 +2958,64 @@
 = plan;%0A
+        this.myData.setSchedule(this.schedule);%0A
     %7D%0A%0A 
@@ -3603,24 +3603,24 @@
 tring id) %7B%0A
-
         this
@@ -3625,24 +3625,481 @@
 is.id = id;%0A
+        this.myData.setEsID(this.id);%0A    %7D%0A%0A    public HabitTypeMetadata getMyData() %7B%0A        return myData;%0A    %7D%0A%0A    public String getUserID() %7B%0A        return userID;%0A    %7D%0A%0A    public void setUserID(String userID) %7B%0A        this.userID = userID;%0A    %7D%0A%0A    public HabitEvent getMostRecentEvent() %7B%0A        return mostRecentEvent;%0A    %7D%0A%0A    public void setMostRecentEvent(HabitEvent mostRecentEvent) %7B%0A        this.mostRecentEvent = mostRecentEvent;%0A
     %7D%0A%0A    @

add userID, ht metadata, and canBeScheduled checks to ht