<?php

namespace App\Http\Controllers\Admin;

use App\Helper\BreadcrumbsRegister;
use App\DataTables\Admin\QaLeadDataTable;
use App\Http\Requests\Admin;
use App\Http\Requests\Admin\CreateQaLeadRequest;
use App\Http\Requests\Admin\UpdateQaLeadRequest;
use App\Models\Lead;
use App\Repositories\Admin\QaLeadRepository;
use App\Http\Controllers\AppBaseController;
use Laracasts\Flash\Flash;
use Illuminate\Http\Response;

class QaLeadController extends AppBaseController
{
    /** ModelName */
    private $ModelName;

    /** BreadCrumbName */
    private $BreadCrumbName;

    /** @var  QaLeadRepository */
    private $qaLeadRepository;

    public function __construct(QaLeadRepository $qaLeadRepo)
    {
        $this->qaLeadRepository = $qaLeadRepo;
        $this->ModelName = 'qa-leads';
        $this->BreadCrumbName = 'Qa Leads';
    }

    /**
     * Display a listing of the QaLead.
     *
     * @param QaLeadDataTable $qaLeadDataTable
     * @return Response
     */
    public function index(QaLeadDataTable $qaLeadDataTable)
    {
        BreadcrumbsRegister::Register($this->ModelName,$this->BreadCrumbName);
        return $qaLeadDataTable->render('admin.qa_leads.index', ['title' => $this->BreadCrumbName]);
    }

    /**
     * Show the form for creating a new QaLead.
     *
     * @return Response
     */
    public function create()
    {
        BreadcrumbsRegister::Register($this->ModelName,$this->BreadCrumbName);
        $leads = Lead::pluck('id', 'id')->all();
        $payment = Lead::pluck('id', 'id')->all();
        $status = ['Verified' => 'Verified', 'Not responding' => 'Not Responding', 'Voice Mail' => 'Voice Mail', 'Unavailable' => 'Unavailable', 'Not Answering' => 'Not Answering', 'Not Interested' => 'Not Interested'
            , 'Language Barrier' => 'Language Barrier' , 'Straight Hang Up' => 'Straight Hang Up'];
        return view('admin.qa_leads.create')->with(['title' => $this->BreadCrumbName])->with(compact('leads'))->with(compact('status'))->with(compact('payment'));
    }

    /**
     * Store a newly created QaLead in storage.
     *
     * @param CreateQaLeadRequest $request
     *
     * @return Response
     */
    public function store(CreateQaLeadRequest $request)
    {
        $qaLead = $this->qaLeadRepository->saveRecord($request);

        Flash::success($this->BreadCrumbName . ' saved successfully.');
        if (isset($request->continue)) {
            $redirect_to = redirect(route('admin.qa-leads.create'));
        } elseif (isset($request->translation)) {
            $redirect_to = redirect(route('admin.qa-leads.edit', $qaLead->id));
        } else {
            $redirect_to = redirect(route('admin.qa-leads.index'));
        }
        return $redirect_to->with([
            'title' => $this->BreadCrumbName
        ]);
    }

    /**
     * Display the specified QaLead.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $qaLead = $this->qaLeadRepository->findWithoutFail($id);

        if (empty($qaLead)) {
            Flash::error($this->BreadCrumbName . ' not found');
            return redirect(route('admin.qa-leads.index'));
        }

        BreadcrumbsRegister::Register($this->ModelName,$this->BreadCrumbName, $qaLead);
        return view('admin.qa_leads.show')->with(['qaLead' => $qaLead, 'title' => $this->BreadCrumbName]);
    }

    /**
     * Show the form for editing the specified QaLead.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $qaLead = $this->qaLeadRepository->findWithoutFail($id);

        if (empty($qaLead)) {
            Flash::error($this->BreadCrumbName . ' not found');
            return redirect(route('admin.qa-leads.index'));
        }
        $status = ['Verified' => 'Verified', 'Not responding' => 'Not Responding', 'Voice Mail' => 'Voice Mail', 'Unavailable' => 'Unavailable', 'Not Answering' => 'Not Answering', 'Not Interested' => 'Not Interested'
            , 'Language Barrier' => 'Language Barrier' , 'Straight Hang Up' => 'Straight Hang Up'];
        BreadcrumbsRegister::Register($this->ModelName,$this->BreadCrumbName, $qaLead);
        return view('admin.qa_leads.edit')->with(['qaLead' => $qaLead, 'title' => $this->BreadCrumbName])->with(compact('status'));
    }

    /**
     * Update the specified QaLead in storage.
     *
     * @param  int              $id
     * @param UpdateQaLeadRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateQaLeadRequest $request)
    {
        $qaLead = $this->qaLeadRepository->findWithoutFail($id);

        if (empty($qaLead)) {
            Flash::error($this->BreadCrumbName . ' not found');
            return redirect(route('admin.qa-leads.index'));
        }

        $qaLead = $this->qaLeadRepository->updateRecord($request, $qaLead);

        Flash::success($this->BreadCrumbName . ' updated successfully.');
        if (isset($request->continue)) {
            $redirect_to = redirect(route('admin.qa-leads.create'));
        } else {
            $redirect_to = redirect(route('admin.qa-leads.index'));
        }
        return $redirect_to->with(['title' => $this->BreadCrumbName]);
    }

    /**
     * Remove the specified QaLead from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $qaLead = $this->qaLeadRepository->findWithoutFail($id);

        if (empty($qaLead)) {
            Flash::error($this->BreadCrumbName . ' not found');
            return redirect(route('admin.qa-leads.index'));
        }

        $this->qaLeadRepository->deleteRecord($id);

        Flash::success($this->BreadCrumbName . ' deleted successfully.');
        return redirect(route('admin.qa-leads.index'))->with(['title' => $this->BreadCrumbName]);
    }
}
