<?php

namespace App\Console\Commands;

use App\Jobs\ProcessMarkdownJob;
use App\Services\QuestionImportService;
use Illuminate\Console\Command;

class ImportMarkdownCommand extends Command
{
    protected $signature = 'question:import-markdown {path}';
    protected $description = 'Import markdown questions into pre_question_candidates';

    public function handle(QuestionImportService $service): int
    {
        $path = (string) $this->argument('path');

        $result = $service->importMarkdown($path);

        ProcessMarkdownJob::dispatch($result->importId, $result->sourceFileId);

        $this->info(sprintf(
            'Queued markdown import. source_file_id=%d import_id=%d',
            $result->sourceFileId,
            $result->importId
        ));

        return self::SUCCESS;
    }
}
