<?php

namespace Bixo\Niche\Policies;

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

class NichePolicy
{


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

        return $niche->is_owner;
    }

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

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

        return $niche->is_owner;
    }

    /**
     * Determine if the given user can delete the given niche.
     *
     * @param Authenticatable $user
     *
     * @return bool
     */
    public function destroy(Authenticatable $user, Niche $niche)
    {
        return $niche->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;
        }
    }
}