<?php

namespace Litematrimony\Profile\Http\Controllers;

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

class ProfilePublicController extends BaseController
{
    // use ProfileWorkflow;

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

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


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

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


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

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

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

}