/*
 * ICESOFT COMMERCIAL SOURCE CODE LICENSE V 1.1
 *
 * The contents of this file are subject to the ICEsoft Commercial Source
 * Code License Agreement V1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the
 * License at
 * http://www.icesoft.com/license/commercial-source-v1.1.html
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations under
 * the License.
 *
 * Copyright 2009-2015 ICEsoft Technologies Canada, Corp. All Rights Reserved.
 */
package com.icesoft.faces.facelets.example.schedule;


import com.icesoft.faces.facelets.component.schedule.CalendarViewService;
import com.icesoft.faces.facelets.component.schedule.model.CalendarEvent;

import java.io.Serializable;
import java.util.*;

/**
 * Mock implementation of CalendarViewService.
 * <p/>
 * In production this class should be replaced with one that ties in with a
 * service layer.
 *
 * @author ICEfaces Technologies Inc.
 */
public class ScheduleExampleBean implements CalendarViewService, Serializable {

    // year view test data.
    private List<CalendarEvent> yearEvents;

    // month view test data
    private List<CalendarEvent> monthEvents;

    // week view test data
    private List<CalendarEvent> weekEvents;

    // day view test data
    private List<CalendarEvent> dayEvents;

    // consistent test data
    private List<CalendarEvent> testEvents;

    // Used to simulate UTC dates retrieved from a back end.
    // These dates are formatted for the GUI based on the User TimeZone.
    GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("UTC"));

    public ScheduleExampleBean() {
        // Add lunch for the current day
        CalendarEvent utcNoonHour = new CalendarEvent();
        utcNoonHour.setDescription("UTC Noon Hour");
        gc.set(gc.get(GregorianCalendar.YEAR), gc.get(GregorianCalendar.MONTH),
                gc.get(GregorianCalendar.DAY_OF_MONTH), 12, 0);
        Date tmp = gc.getTime();
        utcNoonHour.setStartDate(tmp);
        gc.set(gc.get(GregorianCalendar.YEAR), gc.get(GregorianCalendar.MONTH),
                gc.get(GregorianCalendar.DAY_OF_MONTH), 13, 0);
        tmp = gc.getTime();
        utcNoonHour.setEndDate(tmp);
        utcNoonHour.setCalEventId(41);
        // Add All Day event for the current day
        CalendarEvent vacationDay = new CalendarEvent();
        vacationDay.setDescription("Vacation Day");
        gc.set(gc.get(GregorianCalendar.YEAR), gc.get(GregorianCalendar.MONTH),
                gc.get(GregorianCalendar.DAY_OF_MONTH));
        tmp = gc.getTime();
        vacationDay.setStartDate(tmp);
        vacationDay.setEndDate(tmp);
        vacationDay.setAllDay(true);
        vacationDay.setCalEventId(42);

        // initialize a list of calEvents to work with
        initializeYearEvents();
        // initialize a list of calEvents to work with
        initializeMonthEvents();
        // initialize a list of calEvents to work with
        initializeWeekEvents();
        // initialize a list of calEvents to work with
        initializeDayEvents();

        // consistent data for all four views;
        testEvents = new ArrayList<CalendarEvent>();
        testEvents.add(utcNoonHour);
        testEvents.add(vacationDay);
        testEvents.addAll(yearEvents);
        testEvents.addAll(monthEvents);
        testEvents.addAll(weekEvents);
        testEvents.addAll(dayEvents);
    }

    /**
     * Gets all the events for the current users for the given Year
     * that makes up the dateCursor.
     *
     * @param dateCursor users current date view; year.
     * @return list of all events for the given year
     */
    public List<CalendarEvent> getCalendarYearEvents(Calendar dateCursor) {
//        return yearEvents;
        return testEvents;
    }


    /**
     * Gets all the events for the current user for the given Month
     *
     * @param dateCursor users current date view; year and month.
     * @return list of all events for the given month
     */
    public List<CalendarEvent> getCalendarMonthEvents(Calendar dateCursor) {
//        return monthEvents;
        return testEvents;
    }


    /**
     * Gets all the events for the current user for the given week value
     * in dateCursor.    The return values should be sorted
     * by startDate and endDate to work correctly with UI.
     *
     * @param dateCursor users current date view; year and month.
     * @return list of all events for the given week sorted by startDate and
     *         endDate of the event.
     */
    public List<CalendarEvent> getCalendarWeekEvents(Calendar dateCursor) {
//        return weekEvents;
        return testEvents;
    }

    /**
     * Gets all the events for the current user for the given day value
     * in dateCursor.    The return values should be sorted
     * by startDate and endDate to work correctly with UI.
     *
     * @param dateCursor users current date view; year and month.
     * @return list of all events for the given day sorted by startDate and
     *         endDate of the event.
     */
    public List<CalendarEvent> getCalendarDayEvents(Calendar dateCursor) {
//        return dayEvents;
        return testEvents;
    }

    /**
     * build some test data to work with, that's why it Mock...
     */
    private void initializeMonthEvents() {
        monthEvents = new ArrayList<CalendarEvent>(10);
        CalendarEvent calEvent = new CalendarEvent();
        calEvent.setDescription("Month Event 3");
        gc.set(2011, 1, 4);
        Date tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2011, 1, 6);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(true);
        calEvent.setCalEventId(1);
        monthEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Month Event 5");
        gc.set(2011, 1, 5);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2011, 1, 6);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(true);
        calEvent.setCalEventId(2);
        monthEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Month Event 1");
        gc.set(2011, 1, 6, 10, 30);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2011, 1, 6, 11, 0);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(3);
        monthEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Month Event 4");
        gc.set(2011, 1, 6);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2011, 1, 8);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(true);
        calEvent.setCalEventId(4);
        monthEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Month Event 2");
        gc.set(2011, 2, 7, 15, 0);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2011, 2, 7, 15, 30);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(5);
        monthEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Month Event 6");
        gc.set(2011, 2, 12, 14, 0);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2011, 2, 12, 14, 30);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(6);
        monthEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Month Event 7");
        gc.set(2011, 2, 14, 9, 0);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2011, 2, 14, 9, 30);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(7);
        monthEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Month Event 8");
        gc.set(2011, 2, 14, 10, 0);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2011, 2, 14, 10, 30);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(8);
        monthEvents.add(calEvent);
    }

    /**
     * build some test data to work with, that's why it Mock...
     */
    private void initializeYearEvents() {
        yearEvents = new ArrayList<CalendarEvent>(10);

        CalendarEvent calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 1");
        calEvent.setDurationMinute(30);
        gc.set(2010, 4, 11, 9, 0);
        Date tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 4, 11, 9, 30);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(9);
        yearEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("HighMark onsite");
        calEvent.setAllDay(true);
        gc.set(2010, 4, 11);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 4, 12);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(10);
        yearEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("test meeting");
        calEvent.setAllDay(true);
        gc.set(2010, 4, 12);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 4, 13);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(11);
        yearEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 19");
        gc.set(2010, 4, 12, 11, 30);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 4, 12, 13, 0);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(12);
        yearEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 20");
        gc.set(2010, 4, 12, 14, 30);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 4, 12, 15, 30);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(13);
        yearEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 22");
        gc.set(2010, 4, 12, 15, 30);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 4, 12, 16, 0);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(14);
        yearEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Japanese meeting");
        gc.set(2010, 4, 12, 23, 0);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 4, 12, 23, 30);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(15);
        yearEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 2");
        gc.set(2010, 4, 14, 10, 0);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 4, 14, 12, 0);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(16);
        yearEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 6");
        gc.set(2010, 4, 14, 13, 0);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 4, 14, 14, 30);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(17);
        yearEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 9");
        gc.set(2010, 4, 16, 11, 0);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 4, 16, 12, 0);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(18);
        yearEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 3");
        calEvent.setAllDay(true);
        gc.set(2010, 3, 29);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 4, 2);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(19);
        yearEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Month Event 13");
        calEvent.setAllDay(true);
        gc.set(2010, 4, 25);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 4, 25);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(20);
        yearEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Month Event 14");
        calEvent.setAllDay(true);
        gc.set(2010, 4, 25);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 4, 25);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(21);
        yearEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 4");
        calEvent.setAllDay(true);
        gc.set(2010, 4, 30);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 5, 3);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setCalEventId(22);
        yearEvents.add(calEvent);

    }

    /**
     * build some test data to work with, that's why it Mock...
     */
    private void initializeWeekEvents() {
        weekEvents = new ArrayList<CalendarEvent>(10);

        CalendarEvent calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 1");
        gc.set(2010, 9, 19);
        Date tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 9, 21);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(true);
        calEvent.setCalEventId(23);
        weekEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 6");
        gc.set(2010, 9, 19);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 9, 22);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(true);
        calEvent.setCalEventId(24);
        weekEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 9");
        gc.set(2010, 9, 20);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 9, 21);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(true);
        calEvent.setCalEventId(25);
        weekEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 12");
        gc.set(2010, 9, 22);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 9, 23);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(true);
        calEvent.setCalEventId(26);
        weekEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 7");
        gc.set(2010, 9, 20);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 9, 21);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(true);
        calEvent.setCalEventId(27);
        weekEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 2, working form home then some other");
        gc.set(2010, 9, 18, 8, 30);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 9, 18, 10, 0);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(false);
        calEvent.setCalEventId(28);
        weekEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("supperfragacalalisticsuper test case 5. ");
        gc.set(2010, 9, 18, 11, 0);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 9, 18, 11, 30);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(false);
        calEvent.setCalEventId(29);
        weekEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 4");
        gc.set(2010, 9, 19, 13, 30);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 9, 19, 14, 0);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(false);
        calEvent.setCalEventId(30);
        weekEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 5");
        gc.set(2010, 9, 21, 13, 30);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 9, 21, 14, 30);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(false);
        calEvent.setCalEventId(31);
        weekEvents.add(calEvent);
    }

    /**
     * build some test data to work with, that's why it Mock...
     */
    private void initializeDayEvents() {
        dayEvents = new ArrayList<CalendarEvent>(10);

        CalendarEvent calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 1");
        gc.set(2010, 10, 19);
        Date tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 10, 21);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(true);
        calEvent.setCalEventId(32);
        dayEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 6");
        gc.set(2010, 10, 19);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 10, 22);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(true);
        calEvent.setCalEventId(33);
        dayEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 9");
        gc.set(2010, 10, 20);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 10, 21);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(true);
        calEvent.setCalEventId(34);
        dayEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 12");
        gc.set(2010, 10, 22);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 10, 23);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(true);
        calEvent.setCalEventId(35);
        dayEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 7");
        gc.set(2010, 10, 20);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 10, 21);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(true);
        calEvent.setCalEventId(36);
        dayEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 2, working form home then some other");
        gc.set(2010, 10, 18, 8, 30);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 10, 18, 10, 0);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(false);
        calEvent.setCalEventId(37);
        dayEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("supperfragacalalisticsuper test case 5. ");
        gc.set(2010, 10, 18, 11, 0);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 10, 18, 11, 30);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(false);
        calEvent.setCalEventId(38);
        dayEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 4");
        gc.set(2010, 10, 19, 13, 30);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 10, 19, 14, 0);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(false);
        calEvent.setCalEventId(39);
        dayEvents.add(calEvent);

        calEvent = new CalendarEvent();
        calEvent.setDescription("Test Event 5");
        gc.set(2010, 10, 21, 13, 30);
        tmp = gc.getTime();
        calEvent.setStartDate(tmp);
        gc.set(2010, 10, 21, 14, 30);
        tmp = gc.getTime();
        calEvent.setEndDate(tmp);
        calEvent.setAllDay(false);
        calEvent.setCalEventId(40);
        dayEvents.add(calEvent);

    }
}
