<?php

namespace Litecms\Property\Http\Controllers;

use App\Http\Controllers\PublicController as BaseController;
use Litecms\Property\Interfaces\PropertyTypeRepositoryInterface;

class PropertyTypePublicController extends BaseController
{
    // use PropertyTypeWorkflow;

    /**
     * Constructor.
     *
     * @param type \Litecms\PropertyType\Interfaces\PropertyTypeRepositoryInterface $property_type
     *
     * @return type
     */
    public function __construct(PropertyTypeRepositoryInterface $property_type)
    {
        $this->repository = $property_type;
        parent::__construct();
    }

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


        return $this->response->title(trans('$property::$property_type.names'))
            ->view('$property::public.property_type.index')
            ->data(compact('$property_types'))
            ->output();
    }

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


        return $this->response->title(trans('$property::$property_type.names'))
            ->view('$property::public.property_type.index')
            ->data(compact('$property_types'))
            ->output();
    }

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

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

}