<?php

namespace App\Modules\BookingUpgrade\Application\Find;

use App\Modules\BookingUpgrade\Domain\ExistsBookingUpgrade;
use App\Modules\BookingUpgrade\Domain\IdBookingUpgrade;
use App\Modules\BookingUpgrade\Domain\BookingUpgradeRepository;
use App\Modules\Shared\Domain\Transaction;

final class BookingUpgradeFinder
{
    public function __construct(
        private BookingUpgradeRepository $repository,
        private Transaction $transaction
    ) {}

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