<?php

namespace App\Console\Commands\Backoffice;

use App\Facades\Backoffice\ContentTypes;
use App\Services\Backoffice\BackofficeService;
use Illuminate\Console\Command;

class ProcessSearch extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'backoffice:process-search {contentType}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '(Re)process the search index for a specific content type';

    /**
     * Execute the console command.
     */
    public function handle(BackofficeService $service)
    {
        $this->info('Starting search index processing...');
        $contentTypeName = $this->argument('contentType');
        $contentType = ContentTypes::find($contentTypeName);
        if (!$contentType) {
            $this->error("Content type '{$contentTypeName}' not found.");
            return 1;
        }
        $contentType->regenerateSearchIndex();
        $this->info('Search index processing completed.');
        return 0;
    }
}
