<?php

namespace Litematrimony\Profile\Http\Controllers;

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

class ShortlistPublicController extends BaseController
{
    // use ShortlistWorkflow;

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

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


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

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


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

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

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

}