#pragma once
#include "PrimitiveLocation.h"

class Map;
class Region;

// At the moment units are not automatically added to chokepoints

/**
 * @brief A chokepoint connects two regions.
 */
class Chokepoint : public PrimitiveLocation
{
public:
  Chokepoint(BWTA::Chokepoint* chokepoint, Region* firstRegion, Region* secondRegion, Map* parent)
    : m_parent(parent)
    , m_chokepoint(chokepoint)
    , m_firstRegion(firstRegion)
    , m_secondRegion(secondRegion)
  {
  }

  Map* getParent() const
  {
    return m_parent;
  }

  virtual BWAPI::Position getCurrentCenter() const
  {
    return m_chokepoint->getCenter();
  }

  // TODO: implement

  virtual std::pair<BWAPI::TilePosition, int> getOldestVisibleTile() const
  {
    throw std::runtime_error("Not implemented");
  }
  virtual BWAPI::TilePosition getRandomTile() const
  {
    throw std::runtime_error("Not implemented");
  }

  virtual bool isInLocation(BWAPI::Position position) const;
  virtual bool isInLocation(BWAPI::TilePosition tile) const;

  std::pair<Region*, Region*> getRegions() 
  {
    return std::make_pair(m_firstRegion, m_secondRegion);
  }
  std::pair<const Region*, const Region*> getRegions() const
  {
    return std::make_pair(m_firstRegion, m_secondRegion);
  }

  const BWTA::Chokepoint* getChokepoint() const
  {
    return m_chokepoint;
  }

protected:
  friend class Map;

  virtual void _output(std::ostream& out) const
  {
    out << "Chokepoint " << m_chokepoint->getCenter();
  }

  Map* const m_parent;
  BWTA::Chokepoint* const m_chokepoint;
  Region* const m_firstRegion;
  Region* const m_secondRegion;
};