<?php

namespace Ebuy\Product\Policies;

use Litepie\User\Interfaces\UserPolicyInterface;
use Ebuy\Product\Models\Brand;

class BrandPolicy
{

    /**
     * Determine if the given user can view the brand.
     *
     * @param UserPolicyInterface $authUser
     * @param Brand $brand
     *
     * @return bool
     */
    public function view(UserPolicyInterface $authUser, Brand $brand)
    {
        if ($authUser->canDo('product.brand.view') && $authUser->isAdmin()) {
            return true;
        }

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

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

    /**
     * Determine if the given user can update the given brand.
     *
     * @param UserPolicyInterface $authUser
     * @param Brand $brand
     *
     * @return bool
     */
    public function update(UserPolicyInterface $authUser, Brand $brand)
    {
        if ($authUser->canDo('product.brand.edit') && $authUser->isAdmin()) {
            return true;
        }

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

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

    /**
     * Determine if the given user can verify the given brand.
     *
     * @param UserPolicyInterface $authUser
     *
     * @return bool
     */
    public function verify(UserPolicyInterface $authUser, Brand $brand)
    {
        if ($authUser->canDo('product.brand.verify')) {
            return true;
        }

        return false;
    }

    /**
     * Determine if the given user can approve the given brand.
     *
     * @param UserPolicyInterface $authUser
     *
     * @return bool
     */
    public function approve(UserPolicyInterface $authUser, Brand $brand)
    {
        if ($authUser->canDo('product.brand.approve')) {
            return true;
        }

        return false;
    }

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