<?php

namespace App\Http\Controllers\BackOffice\Settings;

use Illuminate\View\View;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\ModeleRequest;
use App\Services\Settings\ModeleService;

class ModeleController extends Controller
{
    public function __construct(
        private readonly ModeleService $modeleservice,
    ) {
    }

    /** Show Modele
     * @param Request $request
     * 
     * @return View
     */
    public function index(Request $request): View
    {   
        //Breadcrumb
        $breadcrumb = [
            'paramètres',
            'modèles',
        ];
        // Return a view
        return view('backoffice.settings.modele.index' , [
            'title' => 'Modele',
            'breadcrumb' => $breadcrumb,
        ]);

    }


    /** Display Form Content
     * @param Request $request
     * 
     * @return mixed
     */
    public function showForm(Request $request) :mixed
    {
        // Return form content
        return $this->modeleservice->_showForm((int)$request->rowID);
    }

    /** Get data
     * @return array
     */
    public function getData(): array
    {   
        // Return permissions data
        return $this->modeleservice->_getData();
    }

    /**
     * @param ModeleRequest $request
     * 
     * @return string
     */
    public function setData(ModeleRequest $request): string
    {   

        $response =  $this->modeleservice->_setData($request->all());
        return json_encode($response);
    }

    /**
     * @param Request $request
     * 
     * @return string
     */
    public function deleteData(Request $request): string
    {
        $response =  $this->modeleservice->_deleteData((int)$request->rowID);
        return json_encode($response);
    }
}
