<?php

namespace app\models;

use yii\db\ActiveRecord;

/**
 * MasUserGroup model — maps to table {{%user_group}} → lms_user_group
 *
 * @property int    $id
 * @property string $group_name
 * @property string $permissions  JSON
 * @property string $is_active    Y|N
 */
class MasUserGroup extends ActiveRecord
{
    public static function tableName(): string
    {
        return '{{%user_group}}';
    }

    public function rules(): array
    {
        return [
            [['group_name'], 'required'],
            [['group_name'], 'string', 'max' => 100],
            [['permissions'], 'safe'],
            [['is_active'], 'in', 'range' => ['Y', 'N']],
        ];
    }

    public function attributeLabels(): array
    {
        return [
            'id'          => 'ID',
            'group_name'  => 'Group Name',
            'permissions' => 'Permissions',
            'is_active'   => 'Status',
        ];
    }

    public function getUsers(): \yii\db\ActiveQuery
    {
        return $this->hasMany(User::class, ['user_group_id' => 'id']);
    }
}
