/*
 * 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.component.schedule.model;

import com.icesoft.faces.facelets.component.names.BeanNames;
import com.icesoft.faces.facelets.component.util.CalendarViewUtil;
import com.icesoft.faces.facelets.component.util.Util;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

/**
 * CalendarEvent class is model class.
 * <p/>
 *
 * @author ICEfaces Technologies Inc.
 */
public class CalendarEvent implements Serializable {

    // helper vars for date manipulation
    protected Calendar start;
    protected Calendar end;

    private boolean allDay;
    private String description;
    private int durationHour;
    private Date startDate;
    private Date endDate;
    private int calEventId;
    private int durationMinute;

    public CalendarEvent() {

    }

    public CalendarEvent(CalendarEvent event) {
        calEventId = event.calEventId;
        // create calendar references.
        CalendarViewUtil cvu = (CalendarViewUtil) Util.getManagedBean(BeanNames.CALENDAR_VIEW_UTIL);
        start = cvu.getLocalizedCalendar();
        start.setTime(event.getStartDate());
        end = cvu.getLocalizedCalendar();
        end.setTime(event.getEndDate());
        allDay = event.isAllDay();
        if (allDay) {
            // Set to beginning of day
            start.set(Calendar.HOUR_OF_DAY, 0);
            start.set(Calendar.MINUTE, 0);
            start.set(Calendar.SECOND, 0);
            start.set(Calendar.MILLISECOND, 0);
            end.set(Calendar.HOUR_OF_DAY, 0);
            end.set(Calendar.MINUTE, 0);
            end.set(Calendar.SECOND, 0);
            end.set(Calendar.MILLISECOND, 0);
        }
        description = event.getDescription();
        durationHour = event.getDurationHour();
        startDate = event.getStartDate();
        endDate = event.getEndDate();
        durationMinute = event.getDurationMinute();
    }

    public Calendar getStart() {
        return start;
    }

    public Calendar getEnd() {
        return end;
    }

    public boolean isAllDay() {
        return allDay;
    }

    public void setAllDay(boolean allDay) {
        this.allDay = allDay;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getDurationHour() {
        return durationHour;
    }

    public void setDurationHour(int durationHour) {
        this.durationHour = durationHour;
    }

    public Date getStartDate() {
        return startDate;
    }

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

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public int getCalEventId() {
        return calEventId;
    }

    public void setCalEventId(int calEventId) {
        this.calEventId = calEventId;
    }

    public int getDurationMinute() {
        return durationMinute;
    }

    public void setDurationMinute(int durationMinute) {
        this.durationMinute = durationMinute;
    }
}