<?php

namespace App\Modules\BookingEquipment\Application\Index;

use App\Modules\BookingEquipment\Domain\IndexBookingEquipment;
use App\Modules\BookingEquipment\Domain\IdBookingEquipment;
use App\Modules\BookingEquipment\Domain\BookingEquipmentRepository;
use App\Modules\Shared\Domain\Transaction;

final class BookingEquipmentIndexer
{
    public function __construct(
        private BookingEquipmentRepository $repository,
        private Transaction $transaction
    ) {}

    public function __invoke(
        IdBookingEquipment $idBookingEquipment,
        bool $avoidTransaction = false,
        bool $lockInShare = false
    ) {
        $index = $this->transaction->transactional(
            fn() => $this->repository->find(new IndexBookingEquipment($idBookingEquipment, $lockInShare)),
            $avoidTransaction
        );
        return $index;
    }
}
