<?php

namespace Modules\Setting\Controllers\Admin;

/** Ajax Request */

use App\Services\Response\ResponseService;
use Exception;
use Illuminate\View\View;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use Modules\MainService\Enums\ViewEnum;
use Modules\Setting\Requests\Admin\SettingRequest;
use Modules\Setting\Services\SettingService;

class SettingController extends Controller
{

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

    public function __construct(
        private SettingService $settingService,
    ){}

    /**
     * Display a listing of the countries.
     *
     * @param Request $request
     * @return View
     */
    public function index(Request $request) :View
    {
        $data =
            [
                'head'=>__('settings.head'),
                'view' => ViewEnum::INDEX->value,
                'action'=>route('settings.store'),
                'route'=>$this->viewDirectory,
                'settings'=>$this->settingService->get(),
                'request' => $request,
            ];
        return $this->settingService->render($data);
    }


    /**
     * Update the specified Country in storage.
     * @param SettingRequest $request
     * @return JsonResponse
     */
    public function store(Request $request) :JsonResponse
    {
        $this->settingService->save($request->all());
        $response = [
            'status'=>200,
            'message'=>__('web.success'),
            'data'=> route('settings.index'),
        ];
        return ResponseService::response($response);
    }

}
