<?php

namespace Eform\Instruction\Policies;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Eform\Instruction\Models\Instructions;

class InstructionsPolicy
{

    use InstructionsAction;
    use InstructionsExim;

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

        return $instructions->is_owner;
    }

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

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

        return $instructions->is_owner;
    }

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