package com.example.habitrack;

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

/**
 *
 * HabitTypeController
 *
 * Version 1.03
 *
 * Created by sshussai on 10/21/17.
 *
 *
 */

public class HabitTypeController {

    /**
     * This class is the main interface for the habit type entity. It can create a new habit type
     * and delete it. It can also edit the title, reason, start date or schedule for a given
     * habit type.
     *
     */

    public HabitTypeController(){}

    public void createNewHabitType(String title, String reason,
                                   Calendar startDate, ArrayList<Integer> schedule) {
        HabitType ht = new
                HabitType(HabitTypeStateManager.getHTStateManager().getHabitTypeID());
        ht.setTitle(title);
        ht.setReason(reason);
        ht.setStartDate(startDate);
        ht.setSchedule(schedule);
        HabitTypeStateManager.getHTStateManager().storeHabitType(ht);

    }

    public void deleteHabitType(Integer requestedID) {
        HabitTypeStateManager.getHTStateManager().removeHabitType(requestedID);

    }

    public HabitType getHabitType(Integer requestedID) {
        HabitType ht = HabitTypeStateManager.getHTStateManager().getHabitType(requestedID);
        return ht;
    }

    public static void editHabitTypeTitle(Integer requestedID, String newTitle){
        HabitType ht = HabitTypeStateManager.getHTStateManager().getHabitType(requestedID);

        if(ht != null){
            ht.setTitle(newTitle);
        }
    }

    public static void editHabitTypeReason(Integer requestedID, String newReason){
        HabitType ht = HabitTypeStateManager.getHTStateManager().getHabitType(requestedID);
        if(ht != null){
            ht.setReason(newReason);
        }
    }

    public static void editHabitTypeStartDate(Integer requestedID, Calendar newDate){
        HabitType ht = HabitTypeStateManager.getHTStateManager().getHabitType(requestedID);
        if(ht != null){
            ht.setStartDate(newDate);
        }
    }

    public static void editHabitTypeSchedule(Integer requestedID, ArrayList<Integer> newSchedule){
        HabitType ht = HabitTypeStateManager.getHTStateManager().getHabitType(requestedID);
        if(ht != null){
            ht.setSchedule(newSchedule);
        }
    }

}




@@ -131,10 +131,9 @@
 n 1.
-03
+2
 %0A *%0A
@@ -2306,13 +2306,196 @@
 %0A    %7D%0A%0A
+    public String getHabitTitle(Integer requestedID)%7B%0A        HabitType ht = HabitTypeStateManager.getHTStateManager().getHabitType(requestedID);%0A        return ht.getTitle();%0A    %7D%0A%0A
 %7D%0A%0A%0A%0A

add getHTTitle() function for the habitevent entity