<?php

declare(strict_types=1);

namespace App\Jobs;

use App\Services\Profile\CreatorJourneyService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

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

    public int $tries = 2;

    public int $timeout = 300;

    /**
     * @param  array<int>  $userIds
     */
    public function __construct(public readonly array $userIds)
    {
    }

    public function handle(CreatorJourneyService $journeys): void
    {
        foreach ($this->userIds as $userId) {
            $journeys->rebuildForUser((int) $userId);
        }
    }
}