<?php

if (!function_exists('canAccess')) {
    function canAccess($resource, $action = 'view')
    {
        return \App\Helpers\PermissionHelper::can(auth()->user(), $resource, $action);
    }
}

if (!function_exists('hasAccess')) {
    function hasAccess($resource, $action = null)
    {
        if ($action === null) {
            return \App\Helpers\PermissionHelper::hasAccess(auth()->user(), $resource);
        }
        return \App\Helpers\PermissionHelper::can(auth()->user(), $resource, $action);
    }
}

if (!function_exists('isAdmin')) {
    function isAdmin()
    {
        return auth()->check() && auth()->user()->role === 'admin';
    }
}

if (!function_exists('isComptabilite')) {
    function isComptabilite()
    {
        return auth()->check() && auth()->user()->role === 'comptabilite';
    }
}

if (!function_exists('isMarketing')) {
    function isMarketing()
    {
        return auth()->check() && auth()->user()->role === 'marketing';
    }
}
