<?php

namespace App\Modules\Room\Application\Index;

use App\Modules\Shared\Domain\Transaction;
use App\Modules\Room\Domain\IdRoom;
use App\Modules\Room\Domain\IndexRoom;
use App\Modules\Room\Domain\RoomRepository;
use App\Modules\Shared\Domain\QueryBuilder;

final class RoomIndexer
{
    public function __construct(
        private RoomRepository $repository,
        private Transaction $transaction
    ) {}

    public function __invoke(IdRoom $idRoom, IndexRoomPopulate $populate, bool $lockInShare = false)
    {
        $this->transaction->begin();
        $index = $this->repository->find(new IndexRoom($idRoom, $populate, $lockInShare));
        $this->transaction->commit();
        return $index;
    }
}
