package caltool.caldb;

import caltool.schedule.*;
import caltool.admin.*;
import caltool.options.*;
import mvp.*;
import java.util.Collection;

/****
 *
 * The CalendarDB is the top-level data class for the Calendar Tool.  It
 * encapsulates the following structures: a list of references to the calendars
 * for all registered users; the user, group, and room databases; a global
 * options list containing the calendar options common by default for all
 * users; the user workspace, which in turn contains the collection of active
 * calendars upon which the current user is working.
 *
 */

public class CalendarDB extends Model {

    /**
     * Construct this by constructing and initializing all components.
     */
    public CalendarDB() {
        super(null);
        userDB = new UserDB();
        groupDB = new GroupDB();
        roomDB = new RoomDB();
        globalOptions = new GlobalOptions();
        workspace = new UserWorkSpace();
    }


    /*-*
     * Public service methods.
     */

    /**
     * Return the currently active calendar in the workspace.
     */
    public UserCalendar getCurrentCalendar() {
        return workspace.getCurrent();
    }

    /**
     * Get the currently selected date.  If none, return today's date.
     */
    public Date getSelectedDate() {
        return workspace.getCurrent().getSelectedDate();
    }

    /**
     * Set the currently selected date to the given date.
     */
    public void setSelectedDate(Date date) {
        workspace.getCurrent().setSelectedDate(date);
    }

    /*-*
     * Derived data fields
     */

    /** List of UserCalendars for all registered users */
    protected UserCalendars userCalendars;

    /** Registered user data base */
    protected UserDB userDB;

    /** User group data base */
    protected GroupDB groupDB;

    /** Room data base */
    protected RoomDB roomDB;
    
    /** Set of calendar options common by default for all users, both
        registered and non-registered */
    protected GlobalOptions globalOptions;

    /** Active calendars upon which the current user is working. */
    protected UserWorkSpace workspace;

}