<?php

namespace Bixo\Payment\Policies;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Bixo\Payment\Models\Detail;

class DetailPolicy
{

    use DetailAction;
    use DetailExim;
    use DetailReport;
    use DetailWorkflow;

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

        return $detail->is_owner;
    }

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

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

        return $detail->is_owner;
    }

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