/********************************************************************
 * Copyright © 2006 VHA. All rights reserved
 ********************************************************************/
package gov.va.med.esr.ui.report.action;

import gov.va.med.fw.util.StringUtils;

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

import org.apache.struts.util.LabelValueBean;

/**
 * Helper class for report actions.
 * 
 * @author Muddaiah Ranga
 * @version 3.0
 */
public class ReportActionHelper {
    
    private static List qm10FiscalYears;
    private static List years;
    private static List hours;
    private static List minutes;
    
    public static String getRemoveSpaceAndDash(String string) {
        String rptId = StringUtils.deleteWhitespace(string);
        return StringUtils.remove(rptId,'-');
    }

    public static List getQm10FiscalYears()
    {
        // Initialize the first fiscal year applicable for the QM10 report (i.e. 2002)
        int firstYear = 2002;

        // Determine the current fiscal year.  A fiscal year starts in October for the following
        // calendar year (e.g. 10/1/2006 is the first day for fiscal year 2007).
        int currentYear = Calendar.getInstance().get(Calendar.YEAR);
        int currentMonth = Calendar.getInstance().get(Calendar.MONTH);
        if (currentMonth >= 9) // 9 for October
        {
            currentYear++;
        }

        if(qm10FiscalYears == null)
        {
            qm10FiscalYears = new ArrayList();
            for (int i=firstYear; i <= currentYear; i++)
            {
                String year = Integer.toString(i);
                qm10FiscalYears.add(new LabelValueBean(year,year));
            }
        }
        return qm10FiscalYears;
    }

    public static List getYears() {
        if(years == null) {
            years = new ArrayList();
            int currentYear = Calendar.getInstance().get(Calendar.YEAR);
            for(int i=1; i<20; i++) {
                String year = Integer.toString(currentYear-i);
                years.add(new LabelValueBean(year,year));
            }
        }
        return years;
    }
    
    public static List getHours() {
        if(hours == null) {
            hours = new ArrayList();
            for(int i=1; i<=24; i++) {
                String hour = Integer.toString(i);
                if(hour.length() == 1) hour = "0" + hour;
                hours.add(new LabelValueBean(hour,hour));
            }
        }
        return hours;
    }
    
    public static List getMinutes() {
        if(minutes == null) {
            minutes = new ArrayList();
            for(int i=0; i<=59; i++) {
                String minute = Integer.toString(i);
                if(minute.length() == 1) minute = "0" + minute;
                minutes.add(new LabelValueBean(minute,minute));
            }
        }
        return minutes;
    }
}
