<?php

namespace App\Console\Commands;

use App\Jobs\RunImportMapSyncTask;
use App\Modules\Stock\ImportMap;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\App;

class RunImportMaps extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'import-maps:run';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Queue the file-based import map sync for the current tenant';

    /**
     * Execute the console command.
     */
    public function handle(): int
    {
        // Dispatch per tenant so a slow remote connection for one tenant does not delay the
        // next - the actual import work (and any FTP latency) happens inside the queued job.
        if (App::make(ImportMap::class)->enabled()) {
            RunImportMapSyncTask::dispatch();
        }

        return self::SUCCESS;
    }
}
