<?php

namespace Buyesrfolio\TransactionFile\Policies;

use Litepie\User\Contracts\UserPolicy;
use Buyesrfolio\TransactionFile\Models\TransactionFile;

class TransactionFilePolicy
{

    /**
     * Determine if the given user can view the transaction_file.
     *
     * @param UserPolicy $user
     * @param TransactionFile $transaction_file
     *
     * @return bool
     */
    public function view(UserPolicy $user, TransactionFile $transaction_file)
    {
        if ($user->canDo('transaction_file.transaction_file.view') && $user->isAdmin()) {
            return true;
        }

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

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

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

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

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

    /**
     * Determine if the given user can verify the given transaction_file.
     *
     * @param UserPolicy $user
     * @param TransactionFile $transaction_file
     *
     * @return bool
     */
    public function verify(UserPolicy $user, TransactionFile $transaction_file)
    {
        if ($user->canDo('transaction_file.transaction_file.verify')) {
            return true;
        }

        return false;
    }

    /**
     * Determine if the given user can approve the given transaction_file.
     *
     * @param UserPolicy $user
     * @param TransactionFile $transaction_file
     *
     * @return bool
     */
    public function approve(UserPolicy $user, TransactionFile $transaction_file)
    {
        if ($user->canDo('transaction_file.transaction_file.approve')) {
            return true;
        }

        return false;
    }

    /**
     * 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;
        }
    }
}