<?php

namespace App\Http\Controllers\BackOffice\Settings;

use Illuminate\View\View;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\CartTypeRequest;
use App\Services\Settings\CarTypeService;

class CartTypeController extends Controller
{
    public function __construct(
        private readonly CarTypeService $cartypeservice,
    ) {
    }

    /** Show CartType
     * @param Request $request
     * 
     * @return View
     */
    public function index(Request $request): View
    {   
        //Breadcrumb
        $breadcrumb = [
            'paramètres',
            'type de véhicule',
        ];
        // Return a view
        return view('backoffice.settings.cartype.index' , [
            'title' => 'type de véhicule',
            'breadcrumb' => $breadcrumb,
        ]);

    }


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

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

    /**
     * @param CartTypeRequest $request
     * 
     * @return string
     */
    public function setData(CartTypeRequest $request): string
    {  
        $response =  $this->cartypeservice->_setData($request->all());
        return json_encode($response);
    }

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