<?php

namespace Cleancrm\Advancedcrm\Http\Controllers;

use App\Http\Controllers\PublicController as BaseController;
use Cleancrm\Advancedcrm\Interfaces\RelationTypeRepositoryInterface;

class RelationTypePublicController extends BaseController
{
    // use RelationTypeWorkflow;

    /**
     * Constructor.
     *
     * @param type \Cleancrm\RelationType\Interfaces\RelationTypeRepositoryInterface $relation_type
     *
     * @return type
     */
    public function __construct(RelationTypeRepositoryInterface $relation_type)
    {
        $this->repository = $relation_type;
        parent::__construct();
    }

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


        return $this->response->setMetaTitle(trans('$advancedcrm::relation_type.names'))
            ->view('advancedcrm::relation_type.index')
            ->data(compact('relation_types'))
            ->output();
    }


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

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

}