// Normalize.hpp
//
//     Created on: 01. 03. 2018
//         Author: Jan Uhlik
//    Modified by:
//
// Copyright (c) 2017 Czech Technical University in Prague | Faculty of Information Technology. All rights reserved.
// Git repository: https://gitlab.fit.cvut.cz/algorithms-library-toolkit/automata-library

#ifndef ALIB2_GRAPHNORMALIZE_HPP
#define ALIB2_GRAPHNORMALIZE_HPP

#include <utility>

#include "DefaultTypes.hpp"

namespace common {

class Normalize {
// ---------------------------------------------------------------------------------------------------------------------

 public:

  template<typename TNode>
  static DefaultNodeType normalizeNode(TNode &&node);

  template<typename TEdge>
  static DefaultEdgeType normalizeEdge(TEdge &&edge);

  template<typename TEdge>
  static DefaultWeightedEdgeType normalizeWeightedEdge(TEdge &&edge);

  template<typename TEdge>
  static DefaultCapacityEdgeType normalizeCapacityEdge(TEdge &&edge);

  template<typename TWeight>
  static DefaultWeightType normalizeWeight(TWeight &&weight);

// ---------------------------------------------------------------------------------------------------------------------

  template<typename TCoordinate>
  static ext::pair<DefaultCoordinateType, DefaultCoordinateType> normalizeObstacle(ext::pair<TCoordinate,
                                                                                             TCoordinate> &&obstacle);

};

// =====================================================================================================================

template<typename TNode>
DefaultNodeType Normalize::normalizeNode(TNode &&node) {
  return DefaultNodeType(std::forward<TNode>(node));
}

template<typename TEdge>
DefaultEdgeType Normalize::normalizeEdge(TEdge &&edge) {
  DefaultNodeType first = normalizeNode(edge.first);
  DefaultNodeType second = normalizeNode(edge.second);
  return DefaultEdgeType(std::move(first), std::move(second));
}

template<typename TEdge>
DefaultWeightedEdgeType Normalize::normalizeWeightedEdge(TEdge &&edge) {
  DefaultNodeType first = normalizeNode(edge.first);
  DefaultNodeType second = normalizeNode(edge.second);
  DefaultWeightType weight = normalizeWeight(edge.weight());
  return DefaultWeightedEdgeType(std::move(first), std::move(second), weight);
}

template<typename TEdge>
DefaultCapacityEdgeType Normalize::normalizeCapacityEdge(TEdge &&edge) {
  DefaultNodeType first = normalizeNode(edge.first);
  DefaultNodeType second = normalizeNode(edge.second);
  DefaultWeightType weight = normalizeWeight(edge.capacity());
  return DefaultCapacityEdgeType(std::move(first), std::move(second), weight);
}

template<typename TWeight>
DefaultWeightType Normalize::normalizeWeight(TWeight &&weight) {
  return DefaultWeightType(std::forward<TWeight>(weight));
}

// ---------------------------------------------------------------------------------------------------------------------

template<typename TCoordinate>
ext::pair<DefaultCoordinateType, DefaultCoordinateType> Normalize::normalizeObstacle(ext::pair<TCoordinate,
                                                                                               TCoordinate> &&obstacle) {
  DefaultCoordinateType first = DefaultCoordinateType(obstacle.first);
  DefaultCoordinateType second = DefaultCoordinateType(obstacle.second);
  return ext::make_pair(first, second);
}

// =====================================================================================================================

} // namespace common

#endif //ALIB2_GRAPHNORMALIZE_HPP
