<?php

namespace App\Modules\RoomPassenger\Application\Index;

use App\Modules\Shared\Domain\Transaction;
use App\Modules\RoomPassenger\Domain\IdRoomPassenger;
use App\Modules\RoomPassenger\Domain\IndexRoomPassenger;
use App\Modules\RoomPassenger\Domain\RoomPassengerRepository;
use App\Modules\Shared\Domain\QueryBuilder;

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

    public function __invoke(IdRoomPassenger $idRoomPassenger, IndexRoomPassengerPopulate $populate, bool $lockInShare = false)
    {
        $this->transaction->begin();
        $index = $this->repository->find(new IndexRoomPassenger($idRoomPassenger, $populate, $lockInShare));
        $this->transaction->commit();
        return $index;
    }
}
