<?php

namespace App\Jobs;

use App\Models\MarkdownImport;
use App\Services\QuestionImportService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class ProcessMarkdownJob implements ShouldQueue
{
    use Dispatchable;
    use InteractsWithQueue;
    use Queueable;
    use SerializesModels;

    public function __construct(
        public readonly int $importId,
        public readonly int $sourceFileId
    ) {
    }

    public function handle(QuestionImportService $service): void
    {
        $import = MarkdownImport::find($this->importId);
        if (!$import) {
            return;
        }

        $service->processMarkdownImport(
            $this->importId,
            $this->sourceFileId,
            (string) $import->original_markdown
        );
    }
}
