public function save(Group $group, array $fields = null, $userId = null)
    {
        $eligible = [
            'title',
            'is_ghost',
            'is_meta',
            'ts_created',
            'ts_changed',
            'attributes',
        ];

        if (null === $fields) {
            $fields = $eligible;
        } else {
            $fields = array_intersect($eligible, $fields);
        }

        $values = [];
        foreach ($fields as $field) {
            switch ($field) {

                case 'attributes':
                    $attributes = $group->getAttributes();
                    if (empty($attributes)) {
                        $values[$field] = null;
                    } else {
                        $values[$field] = serialize($attributes);
                    }
                    break;

                case 'is_ghost':
                    $values['is_ghost'] = (int)$group->isGhost();
                    break;

                case 'is_meta':
                    $values['is_meta'] = (int)$group->isMeta();
                    break;

                default:
                    $values[$field] = $group->{$field}; // @todo uses __get() fixme
            }
        }

        $values['ts_changed'] = $group->touch()->format('Y-m-d H:i:s');

        if ($group->getId()) {
            $this->dispatch($group, 'preSave', [], $userId);

            $this
                ->database
                ->merge('ucms_group')
                ->key(['id' => $group->getId()])
                ->fields($values)
                ->execute()
            ;

            $this->dispatch($group, 'save', [], $userId);
        } else {
            $this->dispatch($group, 'preCreate', [], $userId);

            $values['ts_created'] = $values['ts_changed'];

            $id = $this
                ->database
                ->insert('ucms_group')
                ->fields($values)
                ->execute()
            ;

            $group->setId($id);

            $this->dispatch($group, 'create', [], $userId);
        }
    }