''' dbrev.nv_arg can be thought of as a bean or a template.  It
    has only attributes with getters and setters.
'''

import logging
LOG = logging.getLogger(__name__)
# LOG.setLevel(logging.INFO)

# Long lines expected.
# pylint: disable=C0301
# Cyclic imports protected by functions
# pylint: disable=R0401

class NvArg(object):
    '''NvArg class generated from NV_ARGS table.'''
    def __init__(self, namespace_name=None, name=None, value=None, session_id=None):
        self.namespace_name = namespace_name
        self.name = name
        self.value = value
        self.session_id = session_id
        self._namespace = None
        self._session = None

    def __str__(self):
        out = 'NvArg('
        if self.namespace_name != None:
            out += 'namespace_name:' + str(self.namespace_name) + ','
        if self.name != None:
            out += 'name:' + str(self.name) + ','
        if self.value != None:
            out += 'value:' + str(self.value) + ','
        if self.session_id != None:
            out += 'session_id:' + str(self.session_id)
        if out[-1:] == ',':
            out = out[:-1]
        out += ')'
        return out

    def get_namespace(self):
        ''' Getter method for namespace.'''
        if self.namespace_name != None and self._namespace == None:
            from freevolv.models.dbrev import nv_arg_namespaces_table
            self._namespace = nv_arg_namespaces_table.NvArgNamespacesTable.get_instance() \
                .get_one(name=self.namespace_name)
        return self._namespace
    def set_namespace(self, namespace):
        ''' Setter method for namespace.'''
        self._namespace = namespace
    namespace = property(get_namespace, set_namespace)

    def get_session(self):
        ''' Getter method for session.'''
        if self.session_id != None and self._session == None:
            from freevolv.models.dbrev import sessions_table
            self._session = sessions_table.SessionsTable.get_instance() \
                .get_one(oid=self.session_id)
        return self._session
    def set_session(self, session):
        ''' Setter method for session.'''
        self._session = session
    session = property(get_session, set_session)


