<?php

namespace App\Modules\Leads\WebPage\Application\Find;

use App\Modules\Leads\WebPage\Domain\ExistsWebPage;
use App\Modules\Leads\WebPage\Domain\IdWebPage;
use App\Modules\Leads\WebPage\Domain\WebPageRepository;
use App\Modules\Shared\Domain\Transaction;

final class WebPageFinder
{
    public function __construct(
        private WebPageRepository $repository,
        private Transaction $transaction
    ) {}

    public function __invoke(IdWebPage $idWebPage, bool $lockInShare = true)
    {
        $this->transaction->begin();
        $index = $this->repository->find(new ExistsWebPage($idWebPage, $lockInShare));
        $this->transaction->commit();
        return $index;
    }
}
