<?php

use App\Helpers\FirstParty\OpenAI\OpenAI;
use App\Jobs\GenerateArticleFeaturedImageJob;
use App\Jobs\GenerateArticleJob;
use App\Jobs\Tasks\GetNewsSerpTask;
use App\Jobs\Tasks\ParseNewsSerpDomainsTask;
use App\Models\Category;
use App\Models\NewsSerpResult;
use App\Models\Post;
use App\Models\SerpUrl;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/news_serp', function () {
    $category = Category::find(1);
    $news_serp_result = GetNewsSerpTask::handle($category, 'US');
    dd($news_serp_result);
});

Route::get('/news_serp_parse', function () {
    $news_serp_result = NewsSerpResult::find(1);
    $serp_urls = ParseNewsSerpDomainsTask::handle($news_serp_result);
    dd($serp_urls);
});

Route::get('/write_article', function () {
    $serp_url = SerpUrl::find(1);
    $task = GenerateArticleJob::dispatch($serp_url)->onQueue('default')->onConnection('default');

    dd($task);
});

Route::get('/gen_article_image', function () {
    $post = Post::whereNull('featured_image')->where('status', 'draft')->first();
    $task = GenerateArticleFeaturedImageJob::dispatch($post)->onQueue('default')->onConnection('default');

    dd($task);
});

Route::get('/suggest_titles', function () {
    $results = OpenAI::suggestArticleTitles("It's 2019s Electric: How Fisker Is Reinventing The Automotive Industry And \nExpanding Its Business", "Fisker's approach to building electric vehicles is deeply intertwined with \nits overall business philosophy: use less, use better,...s", 1);
    dd($results);
});

Route::get('/write_article_raw', function () {
    $results = OpenAI::writeArticle("Fisker's Vision for the Future of Electric Cars", "Explore Fisker's innovative vision for the future of electric cars and its impact on the automotive industry.", 'Article', 500, 800);
    dd($results);
});

// Route::get('/image_gen', function() {
//   $post =
//   return GenerateArticleFeaturedImageTask::handle("","","","");
// });
