<?php

namespace App\Http\Controllers\Open;

use App\Models\Setting;
use App\Models\TagDescription;
use Illuminate\Http\Request;
use App\Jobs\AiTag;
use App\Http\Controllers\Controller;

class AiTagController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @param Request $request
     * @return void
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function index(Request $request)
    {
        if (Setting::get('apptoken') == $request->header('token')) {
            $tags = TagDescription::where('lang', config('setting.lang'))->whereNull('description')->get();
            if (!$tags->isEmpty()) {
                foreach ($tags as $tag) {
                    $this->dispatch(new AiTag($tag, $request->input('domain')));
                }
            }
        }
    }
}