<?php

declare(strict_types=1);

namespace ImovelZapAi\Publishing\Infrastructure\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use ImovelZapAi\Publishing\Application\Actions\RebuildTenantFeedAction;
use ImovelZapAi\Tenancy\Support\TenantContext;

final class RebuildTenantFeedJob implements ShouldQueue
{
    use Dispatchable;
    use InteractsWithQueue;
    use Queueable;
    use SerializesModels;

    public int $tries = 3;

    public function __construct(
        public readonly string $tenantId,
    ) {
        $this->onQueue((string) config('publishing.queue', 'publishing'));
    }

    public function handle(RebuildTenantFeedAction $rebuild): void
    {
        TenantContext::set($this->tenantId);

        $rebuild->execute($this->tenantId);
    }
}
