/*
 * This file is part of the Owl Positioning System (OwlPS) project.
 * It is subject to the copyright notice and license terms in the
 * COPYRIGHT.t2t file found in the top-level directory of this
 * distribution and at
 *   https://code.lm7.fr/mcy/owlps/src/master/COPYRIGHT.t2t
 * No part of the OwlPS Project, including this file, may be copied,
 * modified, propagated, or distributed except according to the terms
 * contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
 * distributed along with this file, either separately or by replacing
 * this notice by the COPYRIGHT.t2t file's contents.
 */


#ifndef _OWLPS_POSITIONING_BUILDING_HH_
#define _OWLPS_POSITIONING_BUILDING_HH_

class Area ;
class Waypoint ;

#include <string>
#include <ostream>
#include <unordered_set>
#include <unordered_map>

/// Represents a building, containing one or more Area
class Building
{
protected:
  std::string name ;
  /// List of Area contained in the Building
  std::unordered_map<std::string, const Area*> areas ;
  /// List of Waypoint in the Building
  std::unordered_set<Waypoint*> waypoints ;

public:
  Building(const std::string &_name = "Unnamed building"):
    name(_name) {}

  Building(const Building &source):
    name(source.name), areas(source.areas),
    waypoints(source.waypoints) {}

  ~Building(void) ;

  /** @name Read accessors */
  //@{
  const std::string& get_name(void) const ;
  const std::unordered_map<std::string, const Area*>&
  get_areas(void) const ;
  const std::unordered_set<Waypoint*>& get_waypoints(void) const ;
  //@}

  /** @name Write accessors */
  //@{
  void set_name(const std::string &_name) ;
  /// Adds an Area to the [list of areas](@ref #areas)
  void add_area(const Area *const area) ;
  /// Adds a Waypoint to the [list of waypoints](@ref #waypoints)
  void add_waypoint(Waypoint *const wp) ;
  //@}

  /** @name Operators */
  //@{
  Building& operator=(const Building &source) ;
  bool operator==(const Building &source) const ;
  bool operator!=(const Building &source) const ;
  //@}

  /// Displays a Building
  friend std::ostream& operator<<(std::ostream &os, const Building &b) ;
} ;



/* *** Read accessors *** */


inline const std::string& Building::get_name() const
{
  return name ;
}


inline const std::unordered_map<std::string, const Area*>&
Building::get_areas() const
{
  return areas ;
}


inline const std::unordered_set<Waypoint*>&
Building::get_waypoints() const
{
  return waypoints ;
}



/* *** Write accessors *** */


inline void Building::set_name(const std::string &_name)
{
  name = _name ;
}


/**
 * @param wp A pointer to the Waypoint to add. If `wp` is null,
 * nothing will be added.
 */
inline void Building::add_waypoint(Waypoint *const wp)
{
  if (wp)
    waypoints.insert(wp) ;
}



/* *** Operators *** */


inline bool Building::operator!=(const Building &b) const
{
  return !(*this == b) ;
}



#endif // _OWLPS_POSITIONING_BUILDING_HH_
