<?php

namespace Bixo\Location\Policies;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Bixo\Location\Models\Building;

class BuildingPolicy
{

    use BuildingAction;
    use BuildingWorkflow;

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

        return $building->is_owner;
    }

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

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

        return $building->is_owner;
    }

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