protected function parseFieldsets(array $fieldsets, string $resourceKey, array $includes): array
    {
        $includes = array_map(function ($include) use ($resourceKey) {
            return "$resourceKey.$include";
        }, $includes);

        foreach ($fieldsets as $key => $fields) {
            if (is_numeric($key)) {
                unset($fieldsets[$key]);
                $key = $resourceKey;
            }

            $fields = $this->parseFieldset($key, (array) $fields, $includes);
            $fieldsets[$key] = array_unique(array_merge(key_exists($key, $fieldsets) ? (array) $fieldsets[$key] : [], $fields));
        }

        return array_map(function ($fields) {
            return implode(',', $fields);
        }, $fieldsets);
    }