<?php

namespace Modules\Brand\Controllers\Admin;

/** Ajax Request */

use App\Services\Response\ResponseService;
use Illuminate\View\View;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use Modules\Banner\Requests\Admin\BannerRequest;
use Modules\Brand\Requests\Admin\BrandRequest;
use Modules\Brand\Services\BrandService;
use Modules\Type\Services\TypeService;

class BrandController extends Controller
{

    /** Redirect to this path after each operation success*/
    private $redirectSuccessPath= '/admin/brands';
    /** View folder */
    private $viewDirectory= 'admin.brands.';
    //

    public function __construct(
        private BrandService $brandService,
    )
    {}

    /**
     * Display a listing of the brands.
     *
     * @param Request $request
     * @return View
     */
    public function index(Request $request) :View
    {
        $head= __('brands.head');
        $action = route('brands.store');
        $brands = $this->brandService->get();
        return view($this->viewDirectory.'index', get_defined_vars());
    }


    /**
     * Update the specified Banner in storage.
     * @param BannerRequest $request
     * @param int $id
     * @return JsonResponse
     */
    public function store(BrandRequest $request) :JsonResponse
    {
        // dd($request->validated());
        $this->brandService->create($request->validated());
        session()->flash('message', __('dashboard.saveDone'));
        $response = [
            'status'=>200,
            'message'=>__('web.success'),
            'data'=> route('brands.index'),
        ];
        return ResponseService::response($response);
    }


}
