// cashier.C: the Cashier class. (modified from Pump.cc)

#include <iostream.h>
#include "supermarket.h"
#include "departEvent.h"
#include "cashier.h"

double Cashier::serviceTime () {
   if (custInService == 0) {
      cerr << "Error! no cust in service when expected\n";
      return -1.0;
   }
   // CODE: change distribution (now it's a constant)
   return sim->getServiceTimeBase(); 
}   

void Cashier::startService (Cust *cust) {
   // precondition: cashier->freeCashier() is true. 
   
   // Match the customer to cashier.
   custInService = cust;
   const double cashierTime = serviceTime();
   
   // Collect statistics.
   sim->addWaitingTime( sim->getTime() - custInService->getArrivalTime() );
   sim->addServiceTime( cashierTime );

   // Schedule departure event of customer from this cashier.
   DepartureEvent *dep = new DepartureEvent (sim->getTime() + cashierTime);
   dep->setCashier (this);
   sim->insertEvent (dep);
}
