//////////////////////////////////////////////////////////////////////////
//                                                                      //
// MODULE: Parameters               AUTHOR: Tim Sabin                   //
// DESCRIPTION: Parameters is a class that contains all classes that    //
//   were specified in the Parameter Screen. The only way to change a   //
//   value is through the constructor.                                  //
// DATE CREATED: 06/19/1998         LAST UPDATED: 07/10/1998            //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

import BadParameterException;

/** <code>Parameters</code> contains all parameters that were specified
 * on the Parameter Screen. Once this object is constructed, it cannot
 * be changed.<P>When an object receives a Parameters object, it receives
 * the following guarantees:<BR>
 * <UL>
 *        <LI> The period type is WEEKLY, DAILY, or ACCTG_PD.
 *        <LI> The sub period type is either WEEKLY or DAILY.
 *        <LI> The legal number of sub periods is 1 (DAILY) or 1 or greater
 *            (WEEKLY)
 *        <LI> The originText and originNum fields are non-null.
 *        <LI> The length of the destination arrays is equal and >= 1.
 *        <LI> The HASP string is non-null.
 * </UL>
 * @exception    BadParameterException
 */
public class Parameters {
    /** Constant. Defines report type or subtype of WEEKLY. */
    public static final int WEEKLY = 1;
    /** Constant. Defines report type or subtype of DAILY. */
    public static final int DAILY = 2;
    /** Constant. Defines report type of ACCOUNTING PERIOD. */
    public static final int ACCTG_PD = 3;

    private TimePeriod period [];
    private TimePeriod subPeriods [];
    private String originText;
    private String originNum;
    private String destText [];
    private String destNum [];
    private String HASP;
    
    /** Pass all parameters to end user via this constructor.
     * @param    pd        TimePeriod objects
     * @param    subPds    Represents rows in report
     * @param    origin    Origin of mail; a city name
     * @param    orNum    Origin; a facility ID (e.g. "104BX")
     * @param    dests    Array of destination city strings
     * @param    destsNum Array of destination facility IDs
     * @param    VIA        the "via HASP" other than hasp string
     * @param    hasp    The HASP that this mail went through
     * @exception BadParameterException */
    public Parameters (TimePeriod pd [], TimePeriod subPds [],
      String origin, String orNum, String dests [], String destsNum [],
      String hasp) throws BadParameterException {
        // check the dates and times
        // Make sure contract spelled out above is fulfilled
        if ((pd == null) || (subPds == null) || (origin == null) ||
          (orNum == null) || (dests == null) || (destsNum == null) ||
          (hasp == null)) {
            throw (new BadParameterException (
              "One or more null parameters"));
        }
        if ((pd[0].GetType () != TimePeriod.AP) && (pd[0].GetType () !=
          TimePeriod.WEEKLY) && (pd[0].GetType () != TimePeriod.DAILY)) {
            throw (new BadParameterException (
              "Period must by AP, WEEKLY, or DAILY"));
        }
        if ((subPds[0].GetType () != TimePeriod.WEEKLY) &&
          (subPds[0].GetType () != TimePeriod.DAILY)) {
            throw (new BadParameterException (
              "SubPeriods must be WEEKLY or DAILY"));
        }
        if ((subPds[0].GetType () == TimePeriod.DAILY) &&
          (subPds.length != 1)) {
            throw (new BadParameterException (
              "There may only be 1 DAILY SubPeriod"));
        }
        if (dests.length != destsNum.length) {
            throw (new BadParameterException (
              "Destination & Destination Code arrays must be same size"));
        }
        period = pd;
        subPeriods = subPds;
        originText = origin;
        originNum = orNum;
        destText = dests;
        destNum = destsNum;
        HASP = hasp;
    }

    // Access routines - all data elements are read-only
    /** Fetch the report Periods */
    public TimePeriod [] Periods () {
        System.out.println ("Accessing: period [0]:");
        System.out.println ("Start date: " + period [0].PrintDate (period [0].BeginningDate ()));
        System.out.println ("End date: " + period [0].PrintDate (period [0].EndDate ()));
        return period;
    }
    /** Fetch the row periods */
    public TimePeriod [] SubPeriods () {
        System.out.println ("Accessing: subPeriod [0]:");
        System.out.println ("Start date: " + subPeriods [0].PrintDate (subPeriods [0].BeginningDate ()));
        System.out.println ("End date: " + subPeriods [0].PrintDate (subPeriods [0].EndDate ()));
        return subPeriods;
    }
    /** Fetch the name of the originating city */
    public String OriginText () {
        return originText;
    }
    /** Fetch the originating facility ID */
    public String OriginNum () {
        return originNum;
    }
    /** Fetch the name(s) of the destination city(ies) */
    public String [] DestinationText () {
        return destText;
    }
    /** Fetch the facility ID(s) of the destination(s) */
    public String [] DestinationNum () {
        return destNum;
    }
    /** Fetch the name of the "through HASP" */
    public String HASP () {
        return HASP;
    }
}
