# Path: orangengine/models/base/baseobject.py
# class BaseObject(object):
#     """Base class for all (most) objects. This class should almost never be
#     instantiated directly. It contains a few methods that are the available to
#     all sub classes.
#     """
# 
#     def serialize(self):
#         raise NotImplementedError()
# 
#     def to_json(self):
#         """Return a json dump of self returned from self.serialize()
#         """
#         return json.dumps(self.serialize())


from orangengine.models.base import BaseObject
class BaseServiceTerm(BaseObject):

    def __init__(self, name, protocol, port=None):
        """init service term object"""

        self.name = name
        self.protocol = protocol if protocol else "unknown"
        self.port = port if port else "unknown"

    def __getattr__(self, item):

        if item == 'value':
            if isinstance(self.port, BasePortRange):
                return self.protocol, self.port.value
            else:
                return self.protocol, self.port
        else:
            raise AttributeError

    def serialize(self):
        """Searialize self to a json acceptable data structure
        """

        return {
            'name': self.name,
            'protocol': self.protocol,
            'port': self.port,
        }



# Path: orangengine/models/base/baseobject.py
# class BaseObject(object):
#     """Base class for all (most) objects. This class should almost never be
#     instantiated directly. It contains a few methods that are the available to
#     all sub classes.
#     """
# 
#     def serialize(self):
#         raise NotImplementedError()
# 
#     def to_json(self):
#         """Return a json dump of self returned from self.serialize()
#         """
#         return json.dumps(self.serialize())


# Path: orangengine/models/base/baseservice.py
from orangengine.models.base import BaseObject

class BaseServiceTerm(BaseObject):

    def __init__(self, name, protocol, port=None):
        """init service term object"""

        self.name = name
        self.protocol = protocol if protocol else "unknown"
        self.port = port if port else "unknown"

    def __getattr__(self, item):

        if item == 'value':
            if isinstance(self.port, BasePortRange):
                return self.protocol, self.port.value
            else:
                return self.protocol, self.port
        else:
            raise AttributeError

    def serialize(self):
        """Searialize self to a json acceptable data structure
        """

        return {
            'name': self.name,
            'protocol': self.protocol,
            'port': self.port,
        }



class BaseService(BaseObject):