/**
 * license: GPLv3
 * lodge.reservationsystem
*/
package lodge.reservationsystem;

import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;

import lodge.data.Address;
import lodge.data.KitchenTypeEnum;
import lodge.reservation.Reservation;

public final class CabinReservation extends Reservation {

  public CabinReservation() {
    super();
    this.setType('C');
    this.setNumberOfBeds(1);
    this.setKitchen(KitchenTypeEnum.Kitchenette);
  }
  
  public CabinReservation(final Address physical_address) {
    super();
    this.setType('C');
    this.setNumberOfBeds(1);
    this.setKitchen(KitchenTypeEnum.Kitchenette);
    this.setPhysical_address(
        new Address(physical_address.getStreet(), physical_address.getCity(), physical_address.getState(),
            physical_address.getZip()));
  }

  @Override
  public String ReservationType() {
    return "CabinReservation";
  }

  @Override
  public boolean checkValid() throws IllegalArgumentException {
    if (getPhysical_address() == null) {
      throw new IllegalArgumentException(String.format("not valid, physical_address %s", this.getReservation_number()));
    }
    if (getMailing_address() == null) {
      throw new IllegalArgumentException(String.format("not valid, mailing_address: %s", this.getReservation_number()));
    }
    return true;
  }

  @Override
  public float getPricePerNight() {
    return 0.0f;
  }

  // calculate and return the reservation's price
  // Cabin price plus additional fee of $20 for full kitchen and $5 for each
  // additional bathroom
  @Override
  public float calculatePrice() {
    ZonedDateTime enddt = getReservation_end_date().truncatedTo(ChronoUnit.DAYS);
    ZonedDateTime startdt = getReservation_start_date().truncatedTo(ChronoUnit.DAYS);
    long days = ChronoUnit.DAYS.between(startdt, enddt);
    days = (days < 2) ? 1 : days - 1;
    float calcprice = (getSquareFeet() > 900.0f) ? 120.0f + 15.0f : 120.0f;
    if (getKitchen() == KitchenTypeEnum.FullKitchen) {
      calcprice = calcprice + 20.0f;
    }
    if (getNumberOfBathRooms() > 1) {
      setPrice(getPrice() + (getNumberOfBathRooms() * 5.0f));
    }
    calcprice = calcprice * days;
    return calcprice;
  }

}
