#ifndef NLSR_HPP
#define NLSR_HPP

#include <ndn-cpp-dev/face.hpp>
#include <ndn-cpp-dev/security/key-chain.hpp>
#include <ndn-cpp-dev/util/scheduler.hpp>

#include "nlsr_conf_param.hpp"
#include "nlsr_adl.hpp"
#include "nlsr_npl.hpp"
#include "communication/nlsr_im.hpp"
#include "communication/nlsr_dm.hpp"
#include "nlsr_lsdb.hpp"
#include "nlsr_sm.hpp"
#include "route/nlsr_rt.hpp"
#include "route/nlsr_npt.hpp"
#include "route/nlsr_fib.hpp"
#include "utility/nlsr_logger.hpp"
#include "security/nlsr_km.hpp"
#include "communication/nlsr_slh.hpp"



namespace nlsr
{

    using namespace ndn;
    using namespace std;

    class Nlsr
    {
    public:
        Nlsr()
            : io(ndn::make_shared<boost::asio::io_service>())
            , nlsrFace(make_shared<ndn::Face>(io))
            , scheduler(*io)
            , confParam()
            , adl()
            , npl()
            , im()
            , dm()
            , sm()
            , km()
            , isDaemonProcess(false)
            , configFileName("nlsr.conf")
            , nlsrLsdb()
            , adjBuildCount(0)
            , isBuildAdjLsaSheduled(0)
            , isRouteCalculationScheduled(0)
            , isRoutingTableCalculating(0)
            , routingTable()
            , npt()
            , fib()
            , slh(io)
            , nlsrLogger()
        {}

        void nlsrRegistrationFailed(const ndn::Name& name);

        void setInterestFilterNlsr(const string& name);
        void startEventLoop();

        int usage(const string& progname);

        string getConfFileName()
        {
            return configFileName;
        }

        void setConfFileName(const string& fileName)
        {
            configFileName=fileName;
        }

        bool isSetDaemonProcess()
        {
            return isDaemonProcess;
        }

        void setIsDaemonProcess(bool value)
        {
            isDaemonProcess=value;
        }

        ConfParameter& getConfParameter()
        {
            return confParam;
        }

        Adl& getAdl()
        {
            return adl;
        }

        Npl& getNpl()
        {
            return npl;
        }

        ndn::shared_ptr<boost::asio::io_service>& getIo()
        {
            return io;
        }

        ndn::Scheduler& getScheduler()
        {
            return scheduler;
        }

        ndn::shared_ptr<ndn::Face> getNlsrFace()
        {
            return nlsrFace;
        }

        KeyManager& getKeyManager()
        {
            return km;
        }


        interestManager& getIm()
        {
            return im;
        }

        DataManager& getDm()
        {
            return dm;
        }

        SequencingManager& getSm()
        {
            return sm;
        }

        Lsdb& getLsdb()
        {
            return nlsrLsdb;
        }

        RoutingTable& getRoutingTable()
        {
            return routingTable;
        }

        Npt& getNpt()
        {
            return npt;
        }

        Fib& getFib()
        {
            return fib;
        }

        long int getAdjBuildCount()
        {
            return adjBuildCount;
        }

        void incrementAdjBuildCount()
        {
            adjBuildCount++;
        }

        void setAdjBuildCount(long int abc)
        {
            adjBuildCount=abc;
        }

        int getIsBuildAdjLsaSheduled()
        {
            return isBuildAdjLsaSheduled;
        }

        void setIsBuildAdjLsaSheduled(int iabls)
        {
            isBuildAdjLsaSheduled=iabls;
        }


        void setApiPort(int ap)
        {
            apiPort=ap;
        }

        int getApiPort()
        {
            return apiPort;
        }

        int getIsRoutingTableCalculating()
        {
            return isRoutingTableCalculating;
        }

        void setIsRoutingTableCalculating(int irtc)
        {
            isRoutingTableCalculating=irtc;
        }

        int getIsRouteCalculationScheduled()
        {
            return isRouteCalculationScheduled;
        }

        void setIsRouteCalculationScheduled(int ircs)
        {
            isRouteCalculationScheduled=ircs;
        }

        SyncLogicHandler& getSlh()
        {
            return slh;
        }

        NlsrLogger& getNlsrLogger()
        {
            return nlsrLogger;
        }

        void initNlsr();

    private:
        ConfParameter confParam;
        Adl adl;
        Npl npl;
        ndn::shared_ptr<boost::asio::io_service> io;
        ndn::Scheduler scheduler;
        ndn::shared_ptr<ndn::Face> nlsrFace;
        interestManager im;
        DataManager dm;
        SequencingManager sm;
        KeyManager km;
        bool isDaemonProcess;
        string configFileName;
        int apiPort;

        Lsdb nlsrLsdb;
        RoutingTable routingTable;
        Npt npt;
        Fib fib;
        SyncLogicHandler slh;
        NlsrLogger nlsrLogger;

        long int adjBuildCount;
        int isBuildAdjLsaSheduled;
        int isRouteCalculationScheduled;
        int isRoutingTableCalculating;



    };

} //namespace nlsr

#endif
