<?php

namespace App\Modules\BookingExtra\Application\ListByBooking;

use App\Modules\Booking\Domain\IdBooking;
use App\Modules\BookingExtra\Domain\BookingExtraRepository;
use App\Modules\BookingExtra\Domain\ListByBookingBookingExtra;
use App\Modules\Shared\Domain\Transaction;

final class BookingExtraByBookingLister
{
    public function __construct(
        private BookingExtraRepository $repository,
        private Transaction $transaction
    ) {}

    public function __invoke(
        IdBooking $idBooking,
        bool $avoidTransaction = false,
        bool $lockInShare = false
    ) {
        $index = $this->transaction->transactional(
            fn() => $this->repository->search(new ListByBookingBookingExtra($idBooking, $lockInShare)),
            $avoidTransaction
        );
        return $index;
    }
}
