<?php

namespace Bixo\Aml\Policies;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Bixo\Aml\Models\Name;

class NamePolicy
{

    use NameAction;
    use NameReport;
    use NameWorkflow;

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

        return $name->is_owner;
    }

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

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

        return $name->is_owner;
    }

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