<?php

namespace App\Jobs;

use App\Services\AiChat\AiProductIndexService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

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

    public function __construct(
        public int $itemId,
        public bool $remove = false
    ) {
    }

    public function handle(AiProductIndexService $indexService): void
    {
        if ($this->remove) {
            $indexService->removeItem($this->itemId);
            return;
        }

        $indexService->syncItem($this->itemId);
    }
}
