<?php

namespace App\Modules\LodgingPlace\Application\Index;

use App\Modules\Shared\Domain\Transaction;
use App\Modules\LodgingPlace\Domain\IdLodgingPlace;
use App\Modules\LodgingPlace\Domain\IndexLodgingPlace;
use App\Modules\LodgingPlace\Domain\LodgingPlaceRepository;

final class LodgingPlaceIndexer
{
    public function __construct(
        private LodgingPlaceRepository $repository,
        private Transaction $transaction
    ) {}

    public function __invoke(IdLodgingPlace $idLodgingPlace, bool $lockInShare = false)
    {
        $this->transaction->begin();
        $index = $this->repository->find(new IndexLodgingPlace($idLodgingPlace, $lockInShare));
        $this->transaction->commit();
        return $index;
    }
}
