<?php

namespace App\Modules\Payroll\Jobs;

use App\Modules\Admin\Tenancy\Services\TenantContext;
use App\Modules\Payroll\Services\PayrollSnapshotGenerationService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class GeneratePayrollSnapshotsJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

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

    public function handle(TenantContext $tenantContext, PayrollSnapshotGenerationService $generator): void
    {
        $tenantContext->runForTenant($this->tenantId, function () use ($generator): void {
            $generator->generateSnapshots($this->payrollPeriodId);
        });
    }
}
