detailsFactory->build($data); return $this->transactions->run(function () use ($jobId, $data, $details, $recordedBy): int { $job = $this->jobs->find($jobId) ?? throw new ExpenseJobNotFound($jobId); if ($job->isLocked) { throw new ExpenseLocked; } return (int) $this->expenses->save(Expense::record($jobId, $data->userId, $recordedBy, $details))->id(); }); } }