<?php

namespace App\Modules\HR\Recruitment\Support;

use App\Modules\Admin\Tenancy\Services\TenantContext;

final class RecruitmentTenantId
{
    public static function require(): int
    {
        $fromContext = app(TenantContext::class)->tenantId();
        if ($fromContext !== null && $fromContext > 0) {
            return (int) $fromContext;
        }

        $fromAuth = auth()->user()?->tenant_id;
        abort_if($fromAuth === null, 403);

        return (int) $fromAuth;
    }

    public static function actorId(?int $userId): ?int
    {
        if ($userId !== null && $userId > 0) {
            return $userId;
        }

        $authId = auth()->id();

        return $authId ? (int) $authId : null;
    }
}
