/**
  * @param UuidInterface $reservationId
  *
  * @throws CannotGiveBackReservationWhichWasNotGivenAway
  */
 public function giveBack(UuidInterface $reservationId)
 {
     $reservation = $this->reservations->get($reservationId);
     if (!$reservation->isGivenAway()) {
         throw new CannotGiveBackReservationWhichWasNotGivenAway(sprintf('Cannot give back reservation %s which was not given away.', $reservation->id()));
     }
     $this->reservations->remove($reservationId);
 }
 /**
  * @param UuidInterface $reservationId
  * @param \DateTime     $givenAwayAt
  *
  * @throws BookInReservationAlreadyGivenAway
  */
 public function giveAway(UuidInterface $reservationId, \DateTime $givenAwayAt)
 {
     $reservation = $this->reservations->get($reservationId);
     if ($this->reservations->existsAlreadyGivenOfBook($reservation->bookId())) {
         throw new BookInReservationAlreadyGivenAway(sprintf('Book with id %s in reservation with id %s was already given away.', $reservation->bookId(), $reservation->id()));
     }
     $reservation->giveAway($givenAwayAt);
     $this->reservations->save($reservation);
 }
 /** {@inheritdoc} */
 public function get(UuidInterface $bookId)
 {
     $views = [];
     /** @var Reservation $reservation */
     foreach ($this->repository->getAll() as $reservation) {
         if (!$reservation->bookId()->equals($bookId)) {
             continue;
         }
         $views[] = new ReservationView((string) $reservation->id(), $reservation->email(), $reservation->isGivenAway() ? $reservation->givenAwayAt()->format('Y-m-d H:i:s') : null);
     }
     return $views;
 }
 /**
  * @param UuidInterface $reservationId
  * @param UuidInterface $bookId
  * @param string        $email
  */
 public function create(UuidInterface $reservationId, UuidInterface $bookId, $email)
 {
     $this->reservations->save(new Reservation($reservationId, $bookId, $email));
 }