<?php

namespace Bixo\Niche\Policies;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Bixo\Niche\Models\NicheUser;

class NicheUserPolicy
{


    /**
     * Determine if the given user can view the niche_user.
     *
     * @param Authenticatable $user
     * @param NicheUser $niche_user
     *
     * @return bool
     */
    public function view(Authenticatable $user, NicheUser $niche_user)
    {
        if ($authUser->canDo('niche.niche_user.view') && $authUser->isAdmin() || $user->isClient()) {
            return true;
        }

        return $niche_user->is_owner;
    }

    /**
     * Determine if the given user can create a niche_user.
     *
     * @param Authenticatable $user
     *
     * @return bool
     */
    public function create(Authenticatable $user)
    {
        return  $authUser->canDo('niche.niche_user.create');
    }

    /**
     * Determine if the given user can update the given niche_user.
     *
     * @param Authenticatable $user
     * @param NicheUser $niche_user
     *
     * @return bool
     */
    public function update(Authenticatable $user, NicheUser $niche_user)
    {
        if ($user->canDo('niche.niche_user.edit') && $user->isAdmin()) {
            return true;
        }

        return $niche_user->is_owner;
    }

    /**
     * Determine if the given user can delete the given niche_user.
     *
     * @param Authenticatable $user
     *
     * @return bool
     */
    public function destroy(Authenticatable $user, NicheUser $niche_user)
    {
        return $niche_user->is_owner;
    }

    /**
     * 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;
        }
    }
}