<?php

namespace App\Http\Controllers\Admin\Shop;

use App\Datatables\Admin\Shop\TariffsDataTable;
use App\Repositories\Shop\Tariffs;
use Illuminate\Http\Request;

class TariffController extends Controller
{
    public function autocomplete(Request $request, $str = false)
    {
        $str = $str ? $str : $request->input('q');

        return response()->json(Tariffs::autocomplete($str));
    }

    public function index(TariffsDataTable $dataTable)
    {
        return $dataTable->render('Admin.Shop.Tariffs.list');
    }

    public function create()
    {
        $data = Tariffs::init();

        return view('Admin.Shop.Tariffs.create', $data);
    }

    public function show($id)
    {
        $data = [
            'tariff' => Tariffs::getArray($id),
        ];

        return view('Admin.Shop.Tariffs.view', $data);
    }

    public function edit($id)
    {
        $data = Tariffs::init();
        $data['tariff'] = Tariffs::get($id);

        return view('Admin.Shop.Tariffs.edit', $data);
    }

    public function store(Request $request)
    {
        $ret = Tariffs::store($request->all());

        return redirect()->route('Admin.Shop.Tariffs.index');
    }

    public function destroy($id)
    {
        return Tariffs::destroy($id);
    }
}
