<?php

namespace App\Modules\RoomPassenger\Application\Find;

use App\Modules\RoomPassenger\Domain\ExistsRoomPassenger;
use App\Modules\RoomPassenger\Domain\IdRoomPassenger;
use App\Modules\RoomPassenger\Domain\RoomPassengerRepository;
use App\Modules\Shared\Domain\Transaction;

final class RoomPassengerFinder
{
    public function __construct(
        private RoomPassengerRepository $repository,
        private Transaction $transaction
    ) {}

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