<?php

namespace Islhd\Order\Http\Controllers;

use App\Http\Controllers\PublicController as BaseController;
use Islhd\Order\Interfaces\DetailRepositoryInterface;

class DetailPublicController extends BaseController
{
    // use DetailWorkflow;

    /**
     * Constructor.
     *
     * @param type \Islhd\Detail\Interfaces\DetailRepositoryInterface $detail
     *
     * @return type
     */
    public function __construct(DetailRepositoryInterface $detail)
    {
        $this->repository = $detail;
        parent::__construct();
    }

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


        return $this->response->setMetaTitle(trans('order::detail.names'))
            ->view('order::public.detail.index')
            ->data(compact('details'))
            ->output();
    }


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

        return $this->response->setMetaTitle($detail->name . trans('order::detail.name'))
            ->view('order::public.detail.show')
            ->data(compact('detail'))
            ->output();
    }

}