<?php

namespace App\Modules\HR\Attendance\Jobs;

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

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

    public function __construct(
        public readonly int $tenantId,
        public readonly string $fromYmd,
        public readonly string $toYmd,
    ) {}

    public function handle(TenantContext $tenantContext, AttendanceExceptionDetector $detector): void
    {
        $tenantContext->runForTenant($this->tenantId, function () use ($detector): void {
            $detector->detectForTenant($this->tenantId, $this->fromYmd, $this->toYmd);
        });
    }
}
