<?php

namespace Modules\Settings\Models;

use CodeIgniter\Model;

class UserGroupPermissionsModel extends Model
{
    protected $table = 'user_group_permissions';
    protected $primaryKey = 'id';

    protected $allowedFields = ['group_id', 'permission_id'];

    protected $returnType     = 'array';
    protected $useTimestamps  = true;
    protected $useSoftDeletes = true;
    
    protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';
    protected $deletedField  = 'deleted_at';

    public function getGroupPermissions($groupId)
    {
        return $this->select('permissions.*')
            ->join('permissions', 'permissions.id = user_group_permissions.permission_id')
            ->where('group_id', $groupId)
            ->findAll();
    }

}