// Class Definition for Unchangeable Appointments -- those Appointments that are fixed,
//       except by action of the owner
// File:    Unchangeable.java
// Author:  Henry M. Walker
// Date:    March 14, 2002

// List ADT header
public class UnchangeableAppt implements Appointment {
    private String start;  // when the appointment begins
    private String end;    // when the appointment ends
    private String eMailAddresses; // list of all e-mail addresses for this appointment
    private String comment;// the public annotation for this appointment
    private String priComment; // the private annotation for this appointment

    public UnchangeableAppt () {
        // pre:  none
        // post:  an object is created with all data null

    }

    public UnchangeableAppt (String startTime, String endTime, // the beginning and ending times
                 String eMailAddr, // the e-mail address(es) of those with this appointment
                 String annotation,// a publicly displayable note regarding this appointment
                 String note       // a private comment for the owner of this appointment) 
        // pre:  parameters give initial values for appointment
                             ) {
        // post:  an object is created with all data as specified
        start = startTime;
        end = endTime;
        eMailAddresses = eMailAddr;
        comment = annotation;
        priComment = note;
    }

    public String makeAppt (String startTime, String endTime, // the beginning and ending times
                 String eMailAddr, // the e-mail address(es) of those with this appointment
                 String annotation,// a publicly displayable note regarding this appointment
                 String note,      // a private comment for the owner of this appointment
                 char userCode// o = owner, l = logged-in user, u = unknown user
                            ) {
        // pre:  none
        // post: the appointment is updated as appropriate for the appointment type
        //           and user category;
        //       returns string "appointment made" or an error message string
        if (userCode == 'o') {
            start = startTime;
            end = endTime;
            eMailAddresses = eMailAddr;
            comment = annotation;
            priComment = note;
            return "appointment made";
        } else {
            return "sorry:  only owner can adjust unchangeable appointments";
        }
    }

    public void printAppt (char userCode) {
        // pre:  userCode is as described for method makeAppt
        // post: Appointment information are printed on System.out:
        //       owner receives full information for any appointment
        //       logged-in user receives public information
        //       unknown-information receives summary information on type of appointment and
        //           availability
        if (userCode == 'o') {
            System.out.println ("Unchangeable Appointment:");
            System.out.println ("     Start time:  " + start + ";    End time:  " + end);
            System.out.println ("     E-mail list:  " + eMailAddresses);
            System.out.println ("     Public comment:  " + comment);
            System.out.println ("     Private comment:  " + priComment);
            System.out.println ();
        } else if (userCode == 'l') {
            System.out.println ("Unchangeable Appointment:");
            System.out.println ("     Start time:  " + start + ";    End time:  " + end);
            System.out.println ("     Public comment:  " + comment);
        } else {
            System.out.println ("Unchangeable Appointment:");
            System.out.println ("     Start time:  " + start + ";    End time:  " + end);
        }
    }

    public static void main (String argv[]) {
        // provides simple testing for class UnchangeableAppt
        System.out.println ("-->Creating two appointments, the first having null data");

        UnchangeableAppt appt1 = new UnchangeableAppt ();
        UnchangeableAppt appt2 = new UnchangeableAppt ("8:00", // start time
                                                       "9:00", // end time
                                                       "walker@cs.grinnell.edu",// e-mail
                                                       "CSC 153.01", // public comment
                                                       "Make up assignment by Monday"//private note
                                                       );
        System.out.println ("printing of constructed appointments at owner's level");
        appt1.printAppt('o');
        appt2.printAppt('o');

        System.out.println ("\n-->Owner changes appointment 1");
        System.out.println (appt1.makeAppt("10:00", "11:00", 
                                           "walker@grinnell.edu", "CSC223.02",
                                           "Friday's class involves a lab", 'o'));
        System.out.println ("check printing options (owner/user/unknown)");
        appt1.printAppt('o');
        appt1.printAppt('l');
        appt1.printAppt('u');
        
        System.out.println ("\n-->Logged-in user requests change for appointment 1");
        System.out.println (appt1.makeAppt("2:15", "2:45", 
                                           "walker@grinnell.edu", "office hour",
                                           "I want to talk", 'l'));
        System.out.println ("resulting data in appointment 1");
        appt1.printAppt('o');

        System.out.println ("\n-->Unknown user requests change for appointment 1");
        System.out.println (appt1.makeAppt("3:15", "3:45", 
                                           "walker@grinnell.edu", "talk",
                                           "I want to discuss my life", 'u'));
        System.out.println ("resulting data in appointment 1");
        appt1.printAppt('o');
    }

} // UnchangeableAppt

