<?php

namespace Bixo\Feed\Policies;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Bixo\Feed\Models\Interaction;

class InteractionPolicy
{

    use InteractionAction;
    use InteractionReport;
    use InteractionWorkflow;

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

        return $interaction->is_owner;
    }

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

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

        return $interaction->is_owner;
    }

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