package com.uca.bookings;


/**
 * Implement different state of a booking
 *
 * @author Ugo Cesano, Clément Colmerauer
 */
public enum BookingState implements State {
  INITIAL {
    public void cancel(Booking booking) throws UnsupportedOperationException {
      booking.setState(BookingState.CANCELED);
      Booking.removeBooking(booking);
    }


    public void confirm(Booking booking) throws UnsupportedOperationException {
      throw new UnsupportedOperationException("You cannot confirm this booking until it is payed.");
    }


    public void pay(Booking booking) throws UnsupportedOperationException {
      booking.getCustomer().charge(booking.getPrice());
      booking.setState(BookingState.PAYED);
    }
  }, PAYED {
    public void cancel(Booking booking) throws UnsupportedOperationException {
      booking.getCustomer().refund(booking.getPrice());
      booking.setState(BookingState.CANCELED);
      Booking.removeBooking(booking);
    }


    public void confirm(Booking booking) throws UnsupportedOperationException {
      booking.setState(BookingState.CONFIRMED);
    }


    public void pay(Booking booking) throws UnsupportedOperationException {
      throw new UnsupportedOperationException("This booking has already been payed.");
    }
  }, CONFIRMED {
    public void cancel(Booking booking) throws UnsupportedOperationException {
      booking.setState(BookingState.CANCELED);
      Booking.removeBooking(booking);
    }


    public void confirm(Booking booking) throws UnsupportedOperationException {
      throw new UnsupportedOperationException("This booking has already been confirmed.");
    }


    public void pay(Booking booking) throws UnsupportedOperationException {
      throw new UnsupportedOperationException("This booking has already been payed.");
    }
  }, CANCELED {
    public void cancel(Booking booking) throws UnsupportedOperationException {
      throw new UnsupportedOperationException("This booking has already been cancelled.");
    }


    public void confirm(Booking booking) throws UnsupportedOperationException {
      throw new UnsupportedOperationException("This booking has been cancelled.");
    }


    public void pay(Booking booking) throws UnsupportedOperationException {
      throw new UnsupportedOperationException("This booking has been cancelled.");
    }
  };


}
