<?php

namespace App\Http\Controllers\Api;

use App\Enums\ImportDatasourceStatus;
use App\Http\Controllers\Controller;
use App\Jobs\SyncronizeSIMBG;
use App\Models\ImportDatasource;
use App\Traits\GlobalApiResponse;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Http\Request;

class ScrapingController extends Controller
{
    use GlobalApiResponse;
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        $check_datasource = ImportDatasource::where("status", ImportDatasourceStatus::Processing->value)->count();
        if($check_datasource > 0){
            return $this->resError("Failed to execute while processing another scraping");
        }

        // run service artisan command 
        SyncronizeSIMBG::dispatch();
        return $this->resSuccess(["message" => "Success execute scraping service on background, check status for more"]);
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     */
    public function show(string $id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, string $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(string $id)
    {
        //
    }
}
