<?php

namespace App;

use Spatie\Permission\Models\Permission;

trait ExposePermissions
{
    /**
     * Get all user permissions.
     *
     * @return \Illuminate\Support\Collection
     */
    public function getAllPermissionsAttribute()
    {
        return $this->getAllPermissions();
    }

    /**
     * Get all user permissions in a flat array.
     *
     * @return array<string, bool>
     */
    public function getCanAttribute(): array
    {
        $permissions = [];
        foreach (Permission::all() as $permission) {
            $permissions[$permission->name] = auth()->user()?->can($permission->name) ?? false;
        }
        return $permissions;
    }
}
