<?php

namespace Modules\Subscribe\Controllers\Admin;

/** Ajax Request */

use App\Services\Response\ResponseService;
use Exception;
use Illuminate\View\View;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Routing\Redirector;
use Illuminate\Http\RedirectResponse;
use App\Http\Controllers\Controller;
use Modules\Subscribe\Enums\SubscribeStatusEnum;
use Modules\Subscribe\Models\Subscribe;
use Modules\Subscribe\Requests\Admin\SubscribeRequest;
use Modules\Subscribe\Services\SubscribeService;

class SubscribeController extends Controller
{

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

    public function __construct(SubscribeService $subscribeService)
    {
        $this->subscribeService = $subscribeService;
    }

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

    /**
     * return data of the subscribes.
     *
     * @param Request $request
     * @return View
     */
    public function grid(Request $request) :View
    {
        $request->merge(['paginate'=> true]);
        $subscribes= $this->subscribeService->get($request);

        return view($this->viewDirectory.'grid',compact('subscribes'));
    }

    /**
     * Show the form for editing the specified Subscribe.
     *
     * @param  Subscribe  $subscribe
     * @return View
     */
    public function edit(Subscribe $subscribe) :View
    {
        // dd($subscribe->id);
        $data= $this->subscribeService->getItem($subscribe);
        $head= __('subscribes.edit');
        return view( $this->viewDirectory.'form', get_defined_vars() );
    }


}
