generation->update(['status' => TemplateGenerationStatus::Processing]); try { $outputPath = $this->generation->source === TemplateGenerationSource::AiText ? $this->fillFromAiText($templateFillService, $outlineGenerator) : $templateFillService->fill($this->generation); $this->generation->update([ 'status' => TemplateGenerationStatus::Completed, 'output_path' => $outputPath, ]); } catch (Throwable $exception) { $this->generation->update([ 'status' => TemplateGenerationStatus::Failed, 'error_message' => $exception->getMessage(), ]); } } private function fillFromAiText(TemplateFillService $templateFillService, OpenAiCompatibleTextGenerator $outlineGenerator): string { $provider = AiProvider::resolveActiveDefault(); if (! $provider) { throw new RuntimeException('هیچ سرویس هوش مصنوعی فعالی تنظیم نشده است.'); } $outline = $outlineGenerator->generateOutline( $this->generation->template, (string) $this->generation->title, (string) $this->generation->source_text, (int) $this->generation->slide_count, (string) $this->generation->language, $provider, ); return $templateFillService->fillAiGeneration($this->generation, $outline); } }