<?php

namespace App\Models\Concerns;

use App\Enums\PermissionSlug;
use Illuminate\Database\Eloquent\Builder;

trait HasPermissions
{
    public function hasPermission(PermissionSlug $permission): bool
    {
        return $this->role()
            ->whereHas(
                'permissions',
                fn (Builder $query) => $query->where('slug', $permission),
            )
            ->exists();
    }

    public function hasAnyPermission(PermissionSlug ...$permissions): bool
    {
        return $this->role()
            ->whereHas(
                'permissions',
                fn (Builder $query) => $query->whereIn('slug', $permissions),
            )
            ->exists();
    }
}
