#pragma once

#include <list>
#include <memory>
#include <netdb.h>

#include "RemotePeer.hpp"
#include "utils/crypto/aes/AesKey.hpp"
#include "utils/crypto/rsa/RsaPrivateKey.hpp"


/**
 * Information about the current state of our machine.
 * Used everywhere to determinate how to behave.
 * Information contained here may be private, contrary to the "me" attribute holding public data that can be shared.
 */
class Context {
public:
    explicit Context(int socket, addrinfo* broadcastAddressInfo);

    // communication
    int socket;  /// current socket file descriptor, used to communicate
    addrinfo* broadcastAddressInfo;  /// address used to broadcast messages
    std::shared_ptr<RemotePeer> server;  /// peer currently used as the server

    // ourselves
    Peer me;  /// information about our own machine

    // others
    std::list<std::shared_ptr<RemotePeer>> remotePeers {};  /// information about other machines
    std::chrono::high_resolution_clock::time_point latestPeerDiscovery;  /// time of the latest discovered machine

    // cryptography
    drp::util::crypto::RsaPrivateKey cryptoRsaPrivateKey {};  /// the RSA private key
    drp::util::crypto::AesKey256 cryptoAesKey = {};  /// the AES secret key
};
