<?php

namespace Roshan\Roshan\Http\Controllers;

use App\Http\Controllers\PublicWebController as PublicController;
use Roshan\Roshan\Interfaces\RoshanRepositoryInterface;

class RoshanPublicWebController extends PublicController
{
    /**
     * Constructor.
     *
     * @param type \Roshan\Roshan\Interfaces\RoshanRepositoryInterface $roshan
     *
     * @return type
     */
    public function __construct(RoshanRepositoryInterface $roshan)
    {
        $this->repository = $roshan;
        parent::__construct();
    }

    /**
     * Show roshan's list.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function index()
    {
        $roshans = $this->repository->scopeQuery(function($query){
            return $query->orderBy('id','DESC');
        })->paginate();

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

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

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