<?php

namespace App\Http\Controllers\Admin;

use App\CustomerAppealOption;
use App\Http\Controllers\Traits\FilterTrait;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\StoreCustomerAppealOptionsRequest;
use App\Http\Requests\Admin\UpdateCustomerAppealOptionsRequest;

class CustomerAppealOptionsController extends Controller
{
    use FilterTrait;

    /** Model */
    protected $model = CustomerAppealOption::class;

    /** Variable name */
    protected $variableName = 'customer_appeal_option';

    /** Filter model*/
    protected $filterModel = CustomerAppealOption::class;

    /** Query request */
    protected $modelQuery = "whereId";

    /** Pluck key */
    protected $pluckVariable = 'name';

    /**
     * Display a listing of SubscriptionRc.
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        return $this->handleIndex($request);
    }

    /**
     * Show the form for creating new CustomerAppealOption.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        if (! Gate::allows('customer_appeal_option_create')) {
            return abort(401);
        }

        return view('admin.customer_appeal_options.create');
    }

    /**
     * Store a newly created CustomerAppealOption in storage.
     *
     * @param StoreCustomerAppealOptionsRequest  $request
     * @return Response
     */
    public function store(StoreCustomerAppealOptionsRequest $request)
    {
        if (! Gate::allows('customer_appeal_option_create')) {
            return abort(401);
        }

        $customer_appeal_option = CustomerAppealOption::create($request->all());

        return redirect()->route('admin.customer_appeal_options.index');
    }


    /**
     * Show the form for editing CustomerAppealOption.
     *
     * @param int  $id
     * @return Response
     */
    public function edit($id)
    {
        if (! Gate::allows('customer_appeal_option_edit')) {
            return abort(401);
        }

        $customer_appeal_option = CustomerAppealOption::findOrFail($id);

        return view('admin.customer_appeal_options.edit', compact('customer_appeal_option'));
    }

    /**
     * Update CustomerAppealOption in storage.
     *
     * @param UpdateCustomerAppealOptionsRequest  $request
     * @param int  $id
     * @return Response
     */
    public function update(UpdateCustomerAppealOptionsRequest $request, $id)
    {
        if (! Gate::allows('customer_appeal_option_edit')) {
            return abort(401);
        }
        $customer_appeal_option = CustomerAppealOption::findOrFail($id);
        $customer_appeal_option->update($request->all());



        return redirect()->route('admin.customer_appeal_options.index');
    }


    /**
     * Display CustomerAppealOption.
     *
     * @param int  $id
     * @return Response
     */
    public function show($id)
    {
        if (! Gate::allows('customer_appeal_option_view')) {
            return abort(401);
        }

        $customer_appeals = \App\CustomerAppeal::where('customer_appeal_option_id', $id)->get();

        $customer_appeal_option = CustomerAppealOption::findOrFail($id);

        return view('admin.customer_appeal_options.show', compact('customer_appeal_option', 'customer_appeals'));
    }


    /**
     * Remove CustomerAppealOption from storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function destroy($id)
    {
        if (! Gate::allows('customer_appeal_option_delete')) {
            return abort(401);
        }
        $customer_appeal_option = CustomerAppealOption::findOrFail($id);
        $customer_appeal_option->delete();

        return redirect()->route('admin.customer_appeal_options.index');
    }

    /**
     * Delete all selected CustomerAppealOption at once.
     *
     * @param Request $request
     */
    public function massDestroy(Request $request)
    {
        if (! Gate::allows('customer_appeal_option_delete')) {
            return abort(401);
        }
        if ($request->input('ids')) {
            $entries = CustomerAppealOption::whereIn('id', $request->input('ids'))->get();

            foreach ($entries as $entry) {
                $entry->delete();
            }
        }
    }


    /**
     * Restore CustomerAppealOption from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function restore($id)
    {
        if (! Gate::allows('customer_appeal_option_delete')) {
            return abort(401);
        }

        $customer_appeal_option = CustomerAppealOption::onlyTrashed()->findOrFail($id);
        $customer_appeal_option->restore();

        return redirect()->route('admin.customer_appeal_options.index');
    }

    /**
     * Permanently delete CustomerAppealOption from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function perma_del($id)
    {
        if (! Gate::allows('customer_appeal_option_delete')) {
            return abort(401);
        }
        $customer_appeal_option = CustomerAppealOption::onlyTrashed()->findOrFail($id);
        $customer_appeal_option->forceDelete();

        return redirect()->route('admin.customer_appeal_options.index');
    }
}
