<?php

namespace $NAMESPACE$;

use App\Http\Managers\$PASCAL_ENTITY$Manager;
use App\Http\Requests\$PASCAL_ENTITY$Request;
use App\Models\$PASCAL_ENTITY$;
use App\Repositories\$PASCAL_ENTITY$Repository;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Facades\App;
use Illuminate\View\View;
use Illuminate\Routing\Redirector;
use Illuminate\Http\RedirectResponse;

class $PASCAL_ENTITY_PLURAL$Controller extends Controller
{
    /**
     * @var $PASCAL_ENTITY$Repository
     */
    private $PASCAL_ENTITY$Repository $$SNAKE_ENTITY$Repository;

    /**
     * $PASCAL_ENTITY$Controller constructor.
     * @param $PASCAL_ENTITY$Repository $$SNAKE_ENTITY$Repository
     */
    public function __construct($PASCAL_ENTITY$Repository $$SNAKE_ENTITY$Repository)
    {
        $this->$SNAKE_ENTITY$Repository = $$SNAKE_ENTITY$Repository;

        //$this->authorizeResource($PASCAL_ENTITY$::class);
    }

    /**
     * Display a listing of the resource.
     *
     * @return Application|Factory|\Illuminate\Contracts\View\View
     */
    public function index(): Application|Factory|\Illuminate\Contracts\View\View
    {
        return view('$SNAKE_ENTITY$.list', [
            '$SNAKE_ENTITY_PLURAL$' => $this->$SNAKE_ENTITY$Repository->getAll()
        ]);
    }

	/**
	 * Show the form for creating a new $PASCAL_ENTITY$
	 *
     * @return View
	 */
	public function create(): View
    {
        return view('$SNAKE_ENTITY$.form');
	}

    /**
     * Store a newly created resource in storage.
     *
     * @param $PASCAL_ENTITY$Request $request
     * @return RedirectResponse|Redirector|Application
     */
    public function store($PASCAL_ENTITY$Request $request): Application|RedirectResponse|Redirector
    {
        App::make($PASCAL_ENTITY$Manager::class)->save($request->validated());

        return redirect('$SNAKE_ENTITY$')->with('message', 'Successfully created!');
    }

    /**
     * Show the form for editing the specified $RESOURCE$.
     *
     * @param $PASCAL_ENTITY$ $$SNAKE_ENTITY$
     * @return View
     */
    public function edit($PASCAL_ENTITY$ $$SNAKE_ENTITY$): View
    {
        return view('$SNAKE_ENTITY$.form', [
            '$SNAKE_ENTITY$' => $$SNAKE_ENTITY$
        ]);
    }

    /**
     * Display the specified resource.
     *
     * @param $PASCAL_ENTITY$ $$SNAKE_ENTITY$
     * @return View
     */
    public function show($PASCAL_ENTITY$ $$SNAKE_ENTITY$): View
    {
        return view('$SNAKE_ENTITY$.show', [
            '$SNAKE_ENTITY$' => $$SNAKE_ENTITY$
        ]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param $PASCAL_ENTITY$Request $request
     * @param $PASCAL_ENTITY$ $$SNAKE_ENTITY$
     * @return Application|Redirector|RedirectResponse
     */
    public function update($PASCAL_ENTITY$Request $request, $PASCAL_ENTITY$ $$SNAKE_ENTITY$): Application|RedirectResponse|Redirector
    {
        App::make($PASCAL_ENTITY$Manager::class, ['entity' => $$SNAKE_ENTITY$])->save($request->validated());

        return redirect('$SNAKE_ENTITY$')->with('message', 'Successfully updated!');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param $id
     * @return Application|Redirector|RedirectResponse
     */
    public function destroy($id): Application|RedirectResponse|Redirector
    {
        App::make($PASCAL_ENTITY$Manager::class)->delete([$id]);

        return redirect('$SNAKE_ENTITY$')->with('message', 'Successfully deleted!');
    }
}
