public static function exportToFile(
        string $file,
        OutputInterface $output,
        callable $queryItems
    ) {
        $resource = fopen($file, 'w');

        $i = 1;
        $count = 0;
        while (true) {
            $items = $queryItems(Query::create('', $i, 500))->getItems();

            if (empty($items)) {
                break;
            }

            self::writeItemsToResource(
                $resource,
                $items
            );
            self::printPartialCountSaved($output, count($items));

            $count += count($items);
            ++$i;
        }

        fclose($resource);

        return $count;
    }