<?php

namespace Litepie\News\Policies;

use Litepie\User\Contracts\UserPolicy;
use Litepie\News\Models\NewsCategory;

class NewsCategoryPolicy
{

    /**
     * Determine if the given user can view the news_category.
     *
     * @param UserPolicy $user
     * @param NewsCategory $news_category
     *
     * @return bool
     */
    public function view(UserPolicy $user, NewsCategory $news_category)
    {
        if ($user->canDo('news.news_category.view') && $user->isAdmin()) {
            return true;
        }

        return $news_category->user_id == user_id() && $news_category->user_type == user_type();
    }

    /**
     * Determine if the given user can create a news_category.
     *
     * @param UserPolicy $user
     * @param NewsCategory $news_category
     *
     * @return bool
     */
    public function create(UserPolicy $user)
    {
        return  $user->canDo('news.news_category.create');
    }

    /**
     * Determine if the given user can update the given news_category.
     *
     * @param UserPolicy $user
     * @param NewsCategory $news_category
     *
     * @return bool
     */
    public function update(UserPolicy $user, NewsCategory $news_category)
    {
        if ($user->canDo('news.news_category.edit') && $user->isAdmin()) {
            return true;
        }

        return $news_category->user_id == user_id() && $news_category->user_type == user_type();
    }

    /**
     * Determine if the given user can delete the given news_category.
     *
     * @param UserPolicy $user
     * @param NewsCategory $news_category
     *
     * @return bool
     */
    public function destroy(UserPolicy $user, NewsCategory $news_category)
    {
        return $news_category->user_id == user_id() && $news_category->user_type == user_type();
    }

    /**
     * Determine if the given user can verify the given news_category.
     *
     * @param UserPolicy $user
     * @param NewsCategory $news_category
     *
     * @return bool
     */
    public function verify(UserPolicy $user, NewsCategory $news_category)
    {
        if ($user->canDo('news.news_category.verify')) {
            return true;
        }

        return false;
    }

    /**
     * Determine if the given user can approve the given news_category.
     *
     * @param UserPolicy $user
     * @param NewsCategory $news_category
     *
     * @return bool
     */
    public function approve(UserPolicy $user, NewsCategory $news_category)
    {
        if ($user->canDo('news.news_category.approve')) {
            return true;
        }

        return false;
    }

    /**
     * Determine if the user can perform a given action ve.
     *
     * @param [type] $user    [description]
     * @param [type] $ability [description]
     *
     * @return [type] [description]
     */
    public function before($user, $ability)
    {
        if ($user->isSuperuser()) {
            return true;
        }
    }
}