<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\BankSection;
use Illuminate\Http\Request;

class BankSectionController extends Controller
{

    function __construct()
    {
        $this->middleware('role_or_permission:bank section access|bank section create|bank section edit|bank section delete', ['only' => ['index']]);
        $this->middleware('role_or_permission:bank section create', ['only' => ['create', 'store']]);
        $this->middleware('role_or_permission:bank section edit', ['only' => ['edit', 'update']]);
        $this->middleware('role_or_permission:bank section delete', ['only' => ['delete']]);
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $datas = BankSection::all();
        return view('admin.bank.section.index', compact('datas'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */

    public function create()
    {
        return view('admin.bank.section.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */

    public function store(Request $request)
    {
        $request->validate([
            'title' => ['required'],
            'description' => ['required']
        ]);

        BankSection::query()->create($request->all());

        $notification = array(
            'messege' => 'Created successfully',
            'alert-type' => 'success'
        );
        return back()->with($notification);
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $data = BankSection::query()->findOrFail($id);
        return view('admin.bank.section.edit', compact('data'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $data = BankSection::query()->find($id);
        $data->update($request->all());

        $notification = array(
            'messege' => 'Updated successfully',
            'alert-type' => 'success'
        );

        return back()->with($notification);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $data = BankSection::query()->findOrFail($id);
        $data->delete();

        $notification = array(
            'messege' => 'Deleted successfully',
            'alert-type' => 'success'
        );

        return back()->with($notification);
    }
}
