<?php

namespace App\Http\Controllers\BackOffice;

use App\Models\Car;
use Illuminate\Http\Request;
use Illuminate\Contracts\View\View;
use App\Http\Controllers\Controller;
use App\Models\Settings\Destination;
use App\Http\Requests\ReservationRequest;
use App\Services\Settings\ReservationService;

class ReservationController extends Controller
{
    public function __construct(
        private readonly ReservationService $reservationservice,
    ) {
    }

    /** Show Brand
     * @param Request $request
     * 
     * @return View
     */
    public function index(Request $request): View
    {
        //Breadcrumb
        $breadcrumb = [
            'Reservations',
            'Reservation',
        ];

        // Get data
        $cars = Car::where('active', 1)
        ->where('deleted_at', null)
        ->where('status',1)
        ->get();
        $destinations = Destination::where('active', 1)->where('deleted_at', null)->get();

        // dd($cars);

        // Return a view
        return view('backoffice.reservation.index', [
            'title' => 'Reservation',
            'breadcrumb' => $breadcrumb,
            'cars' => $cars,
            'destinations' => $destinations,
        ]);
    }
    public function list(Request $request): View
    {
        //Breadcrumb
        $breadcrumb = [
            'Reservations',
            'Reservation',
            'Listes',
        ];

        // Return a view
        return view('backoffice.reservation.list', [
            'title' => 'Liste des réservations',
            'breadcrumb' => $breadcrumb,
        ]);
    }


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

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

    /**
     * @param ReservationRequest $request
     * 
     * @return string
     */
    public function setData(ReservationRequest $request): string
    {   
        // dd($request->all());
        $response =  $this->reservationservice->_setData($request->all());
        // return json_encode($response);
        return back()->with('success', $response);
    }

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