<?php

namespace App\Modules\HR\Attendance\Jobs;

use App\Modules\Admin\Tenancy\Services\TenantContext;
use App\Modules\HR\Attendance\Services\AttendanceProcessorService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class ProcessBiometricLogsJob implements ShouldQueue
{
    use Dispatchable;
    use InteractsWithQueue;
    use Queueable;
    use SerializesModels;

    public function __construct(
        public readonly int $tenantId,
        public readonly int $biometricDeviceId,
    ) {}

    public function handle(TenantContext $tenantContext, AttendanceProcessorService $processor): void
    {
        $tenantContext->runForTenant($this->tenantId, function () use ($processor): void {
            $processor->processPendingForDevice($this->biometricDeviceId);
        });
    }
}
