<?php

namespace App\Modules\PaxInformation\Application\Find;

use App\Modules\PaxInformation\Domain\ExistsPaxInformation;
use App\Modules\PaxInformation\Domain\IdPaxInformation;
use App\Modules\PaxInformation\Domain\PaxInformationRepository;
use App\Modules\Shared\Domain\Transaction;

final class PaxInformationFinder
{
    public function __construct(
        private PaxInformationRepository $repository,
        private Transaction $transaction
    ) {}

    public function __invoke(
        IdPaxInformation $idPaxInformation,
        bool $avoidTransaction = false,
        bool $lockInShare = false
    ) {
        $index = $this->transaction->transactional(
            fn() => $this->repository->findAlter(new ExistsPaxInformation($idPaxInformation, $lockInShare)),
            $avoidTransaction
        );
        return $index;
    }
}
