<?php

namespace Litematrimony\Profile;

use User;

class Profile
{
    /**
     * $profile object.
     */
    protected $profile;    /**
     * $visit object.
     */
    protected $visit;    /**
     * $shortlist object.
     */
    protected $shortlist;    /**
     * $request object.
     */
    protected $request;

    /**
     * Constructor.
     */
    public function __construct(\Litematrimony\Profile\Interfaces\ProfileRepositoryInterface $profile,        \Litematrimony\Profile\Interfaces\VisitRepositoryInterface $visit,        \Litematrimony\Profile\Interfaces\ShortlistRepositoryInterface $shortlist,        \Litematrimony\Profile\Interfaces\RequestRepositoryInterface $request)
    {
        $this->profile = $profile;        $this->visit = $visit;        $this->shortlist = $shortlist;        $this->request = $request;
    }

    /**
     * Returns count of profile.
     *
     * @param array $filter
     *
     * @return int
     */
    public function count()
    {
        return  0;
    }

    /**
     * Make gadget View
     *
     * @param string $view
     *
     * @param int $count
     *
     * @return View
     */
    public function gadget($view = 'admin.profile.gadget', $count = 10)
    {

        if (User::hasRole('user')) {
            $this->profile->pushCriteria(new \Litepie\Litematrimony\Repositories\Criteria\ProfileUserCriteria());
        }

        $profile = $this->profile->scopeQuery(function ($query) use ($count) {
            return $query->orderBy('id', 'DESC')->take($count);
        })->all();

        return view('profile::' . $view, compact('profile'))->render();
    }    /**
     * Make gadget View
     *
     * @param string $view
     *
     * @param int $count
     *
     * @return View
     */
    public function gadget($view = 'admin.visit.gadget', $count = 10)
    {

        if (User::hasRole('user')) {
            $this->visit->pushCriteria(new \Litepie\Litematrimony\Repositories\Criteria\VisitUserCriteria());
        }

        $visit = $this->visit->scopeQuery(function ($query) use ($count) {
            return $query->orderBy('id', 'DESC')->take($count);
        })->all();

        return view('profile::' . $view, compact('visit'))->render();
    }    /**
     * Make gadget View
     *
     * @param string $view
     *
     * @param int $count
     *
     * @return View
     */
    public function gadget($view = 'admin.shortlist.gadget', $count = 10)
    {

        if (User::hasRole('user')) {
            $this->shortlist->pushCriteria(new \Litepie\Litematrimony\Repositories\Criteria\ShortlistUserCriteria());
        }

        $shortlist = $this->shortlist->scopeQuery(function ($query) use ($count) {
            return $query->orderBy('id', 'DESC')->take($count);
        })->all();

        return view('profile::' . $view, compact('shortlist'))->render();
    }    /**
     * Make gadget View
     *
     * @param string $view
     *
     * @param int $count
     *
     * @return View
     */
    public function gadget($view = 'admin.request.gadget', $count = 10)
    {

        if (User::hasRole('user')) {
            $this->request->pushCriteria(new \Litepie\Litematrimony\Repositories\Criteria\RequestUserCriteria());
        }

        $request = $this->request->scopeQuery(function ($query) use ($count) {
            return $query->orderBy('id', 'DESC')->take($count);
        })->all();

        return view('profile::' . $view, compact('request'))->render();
    }
}