<?php

namespace Bixo\Aml\Policies;

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

class SanctionPolicy
{

    use SanctionAction;
    use SanctionReport;
    use SanctionWorkflow;

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

        return $sanction->is_owner;
    }

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

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

        return $sanction->is_owner;
    }

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