<?php

namespace Litematrimony\Profile\Http\Controllers;

use App\Http\Controllers\PublicController as BaseController;
use Litematrimony\Profile\Interfaces\RequestRepositoryInterface;

class RequestPublicController extends BaseController
{
    // use RequestWorkflow;

    /**
     * Constructor.
     *
     * @param type \Litematrimony\Request\Interfaces\RequestRepositoryInterface $request
     *
     * @return type
     */
    public function __construct(RequestRepositoryInterface $request)
    {
        $this->repository = $request;
        parent::__construct();
    }

    /**
     * Show request's list.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function index()
    {
        $requests = $this->repository
        ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria'))
        ->scopeQuery(function($query){
            return $query->orderBy('id','DESC');
        })->paginate();


        return $this->response->title(trans('$profile::$request.names'))
            ->view('$profile::public.request.index')
            ->data(compact('$requests'))
            ->output();
    }

    /**
     * Show request's list based on a type.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function list($type = null)
    {
        $requests = $this->repository
        ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria'))
        ->scopeQuery(function($query){
            return $query->orderBy('id','DESC');
        })->paginate();


        return $this->response->title(trans('$profile::$request.names'))
            ->view('$profile::public.request.index')
            ->data(compact('$requests'))
            ->output();
    }

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

        return $this->response->title($$request->name . trans('$profile::$request.name'))
            ->view('$profile::public.request.show')
            ->data(compact('$request'))
            ->output();
    }

}