<?php

namespace App\Modules\HR\Recruitment\Listeners;

use App\Modules\HR\Recruitment\Events\RecruitmentCandidateHired;
use App\Modules\HR\Recruitment\Services\OnboardingCaseService;

class StartOnboardingOnHireListener
{
    public function __construct(
        private readonly OnboardingCaseService $onboarding,
    ) {}

    public function handle(RecruitmentCandidateHired $event): void
    {
        $hiring = $event->hiring;
        $userId = (int) ($hiring->hired_by ?? 0);
        if ($userId <= 0) {
            return;
        }

        $this->onboarding->startFromHiring($hiring, $userId);
    }
}
