<?php

namespace App\Jobs\Tasks;

use App\Models\AiTool;
use App\Notifications\PostWasPublished;
use Exception;
use Illuminate\Support\Facades\Notification;
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;
use LaravelGoogleIndexing;

class PublishIndexPostTask
{
    public static function handle(int $ai_tool_id)
    {
        $ai_tool = AiTool::find($ai_tool_id);

        if (is_null($ai_tool)) {
            return;
        }

        if (!$ai_tool->is_ai_tool)
        {
          return ;
        }



      if ((app()->environment() == 'production') && (config('platform.general.indexing'))) {
          $ai_tool_url = route('front.aitool.show', ['ai_tool_slug' => $ai_tool->slug]);

          try {
              IndexNow::submit($ai_tool_url);
          } catch (Exception) {
          }

          try {
              LaravelGoogleIndexing::create()->update($ai_tool_url);
          } catch (Exception) {
          }

      }
    }

}
