<?php

namespace Bixo\Payment\Policies;

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

class InvoicePolicy
{

    use InvoiceAction;
    use InvoiceExim;
    use InvoiceReport;
    use InvoiceWorkflow;

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

        return $invoice->is_owner;
    }

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

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

        return $invoice->is_owner;
    }

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