<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class PlatformRole extends Model
{
    protected $fillable = [
        'name',
        'label',
        'description',
        'permissions',
        'color',
        'is_system',
    ];

    protected $casts = [
        'permissions' => 'array',
        'is_system'   => 'boolean',
    ];

    public function users()
    {
        return $this->hasMany(User::class, 'platform_role_id');
    }

    /** Check whether this role includes a given permission key. */
    public function hasPermission(string $key): bool
    {
        return in_array($key, $this->permissions ?? []);
    }
}
