#ifndef ADJACENT_HPP
#define ADJACENT_HPP

namespace nlsr
{

    using namespace std;

    class Adjacent
    {

    public:
        Adjacent()
            :adjacentName()
            ,connectingFace(0)
            ,linkCost(10.0)
            ,status(0)
            ,interestTimedOutNo(0)
        {
        }

        Adjacent(const string& an)
            :connectingFace(0)
            ,linkCost(0.0)
            ,status(0)
            ,interestTimedOutNo(0)
        {
            adjacentName=an;
        }

        Adjacent(const string& an, int cf, double lc, int s, int iton);

        string getAdjacentName()
        {
            return adjacentName;
        }

        void setAdjacentName(const string& an)
        {
            adjacentName=an;
        }

        int getConnectingFace()
        {
            return connectingFace;
        }

        void setConnectingFace(int cf)
        {
            connectingFace=cf;
        }

        double getLinkCost()
        {
            return linkCost;
        }

        void setLinkCost(double lc)
        {
            linkCost=lc;
        }

        int getStatus()
        {
            return status;
        }

        void setStatus(int s)
        {
            status=s;
        }

        int getInterestTimedOutNo()
        {
            return interestTimedOutNo;
        }

        void setInterestTimedOutNo(int iton)
        {
            interestTimedOutNo=iton;
        }

        bool isAdjacentEqual(Adjacent& adj);
    private:
        string adjacentName;
        int connectingFace;
        double linkCost;
        int status;
        int interestTimedOutNo;
    };

    std::ostream&
    operator << (std::ostream &os, Adjacent &adj);

} // namespace nlsr

#endif
