<?php

namespace App\Modules\Template\TourTemplate\Application\Index;

use App\Modules\Shared\Domain\Transaction;
use App\Modules\Template\TourTemplate\Domain\IdTourTemplate;
use App\Modules\Template\TourTemplate\Domain\IndexTourTemplate;
use App\Modules\Template\TourTemplate\Domain\TourTemplateRepository;

final class TourTemplateIndexer
{
    public function __construct(
        private TourTemplateRepository $repository,
        private Transaction $transaction
    ) {}

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