// Copyright (c) 2012-2013, IGN France.
// Copyright (c) 2012-2024, Oslandia.
// Copyright (c) 2024-2026, SFCGAL team.
// SPDX-License-Identifier: LGPL-2.0-or-later

#ifndef SFCGAL_COLLECT_ALGORITHM
#define SFCGAL_COLLECT_ALGORITHM

#include "SFCGAL/config.h"

#include "SFCGAL/Geometry.h"
#include "SFCGAL/GeometryCollection.h"

namespace SFCGAL::algorithm {
/**
 * Returns an aggregate of ga and gb
 * @param ga the first geometry
 * @param gb the second geometry
 * @return an aggregate of the two geometries as a unique_ptr<Geometry>
 */
SFCGAL_API std::unique_ptr<Geometry>
           collect(const Geometry &ga, const Geometry &gb);

/**
 * Returns an aggregate of a list of geometries
 * @param begin iterator to the beginning of the geometry list
 * @param end iterator to the end of the geometry list
 * @return an aggregate of all geometries as a unique_ptr<Geometry>
 */
template <typename GeometryIterator>
std::unique_ptr<Geometry>
collect(GeometryIterator begin, GeometryIterator end)
{
  GeometryIterator it;
  // FIXME: optimize type. For instance, if all the given geometries are points,
  // return a MultiPoint instead of a GeometryCollection
  auto coll = std::make_unique<GeometryCollection>();

  for (it = begin; it != end; ++it) {
    coll->addGeometry(*it);
  }

  return coll;
}
} // namespace SFCGAL::algorithm

#endif
