<?php

namespace Bixo\Team\Policies;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Bixo\Team\Models\Team;

class TeamPolicy
{


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

        return $team->is_owner;
    }

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

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

        return $team->is_owner;
    }

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