<?php

namespace Bixo\Shop\Policies;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Bixo\Shop\Models\Accessory;

class AccessoryPolicy
{


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

        return $accessory->is_owner;
    }

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

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

        return $accessory->is_owner;
    }

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