<?php

namespace App\Modules\PaxInformationRoomPassenger\Application\Find;

use App\Modules\PaxInformationRoomPassenger\Domain\ExistsPaxInformationRoomPassenger;
use App\Modules\PaxInformationRoomPassenger\Domain\IdPaxInformationRoomPassenger;
use App\Modules\PaxInformationRoomPassenger\Domain\PaxInformationRoomPassengerRepository;
use App\Modules\Shared\Domain\Transaction;

final class PaxInformationRoomPassengerFinder
{
    public function __construct(
        private PaxInformationRoomPassengerRepository $repository,
        private Transaction $transaction
    ) {}

    public function __invoke(
        IdPaxInformationRoomPassenger $idPaxInformationRoomPassenger,
        bool $avoidTransaction = false,
        bool $lockInShare = false
    ) {
        $index = $this->transaction->transactional(
            fn() => $this->repository->find(new ExistsPaxInformationRoomPassenger($idPaxInformationRoomPassenger, $lockInShare)),
            $avoidTransaction
        );
        return $index;
    }
}
