<?php

namespace Assetdocs\Incidentreporting\Http\Controllers;

use App\Http\Controllers\Controller as BaseController;
use Assetdocs\Incidentreporting\Interfaces\IncidentreportingRepositoryInterface;

class IncidentreportingController extends BaseController
{
    /**
     * Constructor.
     *
     * @param type \Assetdocs\Incidentreporting\Interfaces\IncidentreportingRepositoryInterface $incidentreporting
     *
     * @return type
     */
    public function __construct(IncidentreportingRepositoryInterface $incidentreporting)
    {
        $this->middleware('web');
        $this->setupTheme(config('theme.themes.public.theme'), config('theme.themes.public.layout'));

        $this->repository = $incidentreporting;
        parent::__construct();
    }

    /**
     * Show incidentreporting's list.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function index()
    {
        $incidentreportings = $this->repository
            ->pushCriteria(new \Assetdocs\Incidentreporting\Repositories\Criteria\IncidentreportingPublicCriteria())
            ->scopeQuery(function($query){
                return $query->orderBy('id','DESC');
            })->paginate();

        return $this->theme->of('incidentreporting::public.incidentreporting.index', compact('incidentreportings'))->render();
    }

    /**
     * Show incidentreporting.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function show($slug)
    {
        $incidentreporting = $this->repository->scopeQuery(function($query) use ($slug) {
            return $query->orderBy('id','DESC')
                         ->where('slug', $slug);
        })->first(['*']);

        return $this->theme->of('incidentreporting::public.incidentreporting.show', compact('incidentreporting'))->render();
    }
}