<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class PermissionGroup extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'description',
        'permissions',
        'created_by',
        'bypass_ip_auth',
    ];

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

    /**
     * Get users belonging to this permission group
     */
    public function users()
    {
        return $this->hasMany(User::class);
    }

    /**
     * Get the user who created this permission group
     */
    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by');
    }
}
