// network_state.h implements the Network State class which represents a single
// state of a network and cotains a factbase of known truths for the Network
// State

#ifndef NETWORK_STATE_H
#define NETWORK_STATE_H

#include "asset.h"
#include "factbase.h"
#include "quality.h"
#include "topology.h"

#include <boost/archive/tmpdir.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>

#include <boost/serialization/base_object.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/list.hpp>
#include <boost/serialization/assume_abstract.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/vector.hpp>


#include <boost/serialization/is_bitwise_serializable.hpp>

#include "../util/keyvalue.h"
#include "../util/redis_manager.h"

class Network;

/** NetworkState class
 * @brief Manages the current state of the network
 * @details The current network state is dependent on the Qualities
 *          and Topologies in the Factbase. NetworkState allows
 *          for the addition of Qualities and Topologies to the Factbase.
 */
class NetworkState {
    Factbase factbase;
    friend class Factbase;

    friend std::ostream & operator << (std::ostream &os, const NetworkState &nsb);
    friend class boost::serialization::access;

    template<class Archive>
    void serialize(Archive &ar, const unsigned int version){
        ar & factbase;
    }

  public:
    NetworkState(std::vector<Quality> q, std::vector<Topology> t);
    NetworkState(const NetworkState &ns);
    NetworkState();

    const Factbase &get_factbase() const;
    size_t get_hash(Keyvalue &factlist);

    void set_id();
    void force_set_id(int i);
    int get_id();
    int get_size();
    void reset_curr_id();
    void reset_curr_id(int i);
    void add_qualities(std::vector<Quality> q);
    void add_topologies(std::vector<Topology> t);

    void add_quality(Quality &q);
    void add_topology(Topology &t);

    void update_quality(Quality &q);
    void update_topology(Topology &t);
    std::string compound_assign(Quality &q);
    
    void delete_quality(Quality &q);
    void delete_topology(Topology &t);

    //bool operator<(const NetworkState& foo) const {return get_hash(Keyvalue &factlist) < foo.get_hash(Keyvalue &factlist);}
};

BOOST_SERIALIZATION_ASSUME_ABSTRACT(NetworkState)

#endif
