/* File apptcal.tu.  The ApptCalendar data object.
 * The ApptCalendar contains a set of appointments that each consist of
 * a day, time, and message.  The day, start time, and end time of each
 * are unique.  The times are in half-hour increments.
 * Appointments can be booked, fitted, found, and canceled.
 * A day or a week of appointments can be displayed.
 * A day of appointments can be cleared.  The day after the current
 * one can be displayed.
 * The calendar can be saved to a file, and loaded from the file.
 *
 * The format for dates is simply the day of the week, and they must
 * be working days (not Saturday or Sunday).  The start and end times
 * are in 24-hour time, e.g., 14:30 means 2:30 pm.
 */

#include "bool.h"
#include "time.h"
#include "appt.h"

/* The maximum number of appointments each day.*/
#define MAX_APPTS 16
#define DAY_LEN 10	/* length of Wednesday + 1*/

/* The names of valid work days.*/
typedef enum {Monday, Tuesday, Wednesday, Thursday, Friday, Days} Workday;


/* The appointments for a day.  Starting at 09:00, each successive index
 * represents the half-hour slot.
 */
typedef Appointment DayAppts[MAX_APPTS];

/* The calendar type */
typedef struct CalType {
    Workday currentDay;       /* The current day.*/
    DayAppts WorkWeek[Days];  /* The work week. */
    char fileName[30];        /* File in which to store the calendar. */
} Calendar;

/* ApptCalInit()
 *----------------------------------------------------------------
 * Initialize the appointment calendar
 */
void
ApptCalInit(Calendar *C);


/* DisplayDay
 *----------------------------------------------------------------
 */
void
DisplayDay(Workday day);


/* MakeDayFromString
 *----------------------------------------------------------------
 * Convert a string to its Workday enumeration value.
 */
Workday
MakeDayFromString(char *dayStr);

/* CalendarBook
 *----------------------------------------------------------------
 * Book appointment appt on day starting at startTime and ending
 * at endTime.  The appointment must not overlap any already in the
 * calendar.  Set the stored information about the appointment
 * to message.  Set whether the appointed time is fixed according to
 * fixed.  Set success to true if the appointment was booked,
 * false otherwise.
 */
boolean
CalendarBook(Calendar *C, Workday day, ClockTime startTime, ClockTime endTime,
	     char *message, boolean fixed);

/* CalendarFit
 *----------------------------------------------------------------
 * Fit appointment appt by inserting the appointment into
 * the first available time slot that is large enough.  Set the
 * stored information about the appointment to message.  If there is
 * not enough space anywhere, try to move non-fixed appointments
 * around to clear up space.  Set success to true if the appointment
 * was booked, false otherwise.
 */
boolean
CalendarFit(Calendar *C, Workday day, ClockTime totalTime, char *message,
	     boolean fixed, ClockTime *startTime, ClockTime *endTime);

/* CalendarFind
 *----------------------------------------------------------------
 * Find the next appointment that contains message.  Set success
 * to true if an appointment was found, false otherwise.  Set day,
 * startTime, and endTime to the time of the appointment if an
 * appointment was found.
 */
boolean
CalendarFind(Calendar *C, char *message, Workday *day,
	     ClockTime *startTime, ClockTime *endTime);

/* CalendarCancel
 *----------------------------------------------------------------
 * Cancel appointment identified by message.
 */
void
CalendarCancel(Calendar *C, char *message);

/* CalendarClearDay
 *----------------------------------------------------------------
 * Cancel all appointments on the current day.
 */
void
CalendarClearDay(Calendar *C, Workday day);

/* CalendarClearWeek
 *----------------------------------------------------------------
 * Cancel all appointments in the calendar.
 */
void
CalendarClearWeek(Calendar *C);

/* CalendarViewDay
 *----------------------------------------------------------------
 * View all appointments on the requested day.
 */
void
CalendarViewDay(Calendar *C, Workday day);

/* CalendarViewToday
 *----------------------------------------------------------------
 * View all appointments on the current day.
 */
void
CalendarViewToday(Calendar *C);


/* CalendarNextDay
 *----------------------------------------------------------------
 * Clear the appointments on the current day and move on to
 * the next day.
 */
void
CalendarNextDay(Calendar *C);

/* CalendarViewWeek
 *----------------------------------------------------------------
 * View all appointments for the week.
 */
void
CalendarViewWeek(Calendar *C);

/* CalendarSave
 *----------------------------------------------------------------
 * Save to file.
 */
void
CalendarSave(Calendar *C);

/* CalendarLoad
 *----------------------------------------------------------------
 * Load from file.
 */
void
CalendarLoad(Calendar *C);
