<?php

namespace App\Modules\DefinedService\OfficesBriefing\Application\Index;

use App\Modules\DefinedService\OfficesBriefing\Domain\BriefingOfficeRepository;
use App\Modules\DefinedService\OfficesBriefing\Domain\IdBriefingOffice;
use App\Modules\DefinedService\OfficesBriefing\Domain\IndexBriefingOffice;
use App\Modules\Shared\Domain\Transaction;

final class OfficesBriefingIndexer
{
    public function __construct(
        private BriefingOfficeRepository $repository,
        private Transaction $transaction
    ) {}

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