"""
Objects generated by the parser
"""

class _Object(object):
    """
    Root class of objects

    Has a `.name`
    """
    def __init__(self):
        self.name = None

    def __repr__(self):
        return "<{}({})>".format(self.__class__.__name__, str(self))


class Docstring(_Object):
    """Holds a docstring

    Has a `.content`"""
    def __init__(self, content):
        _Object.__init__(self)
        self.content = content

    def __str__(self):
        return self.content


class Module(_Object):
    """Module

    Has a `.docstring` (defaults to `None`) and a `.content` (list of _Object subclass instances)"""
    def __init__(self):
        _Object.__init__(self)
        self.docstring = None
        self.content = list()

    def __str__(self):
        return self.name


class Class(_Object):
    """Class

    Has `.parents` (name of parent classes), `.docstring`, `.constructor` and `.content`
    """
    def __init__(self):
        _Object.__init__(self)
        self.parents = list()
        self.docstring = None
        self.constructor = None
        self.content = list()

    def __str__(self):
        if self.constructor is not None:
            return '{}({})'.format(self.name, ', '.join(str(a) for a in self.constructor.arguments))
        return '{}()'.format(self.name)


class Argument(_Object):
    """Argument to functions

    Has a `.default` value (that can be `None`)
    """
    def __init__(self):
        _Object.__init__(self)
        self.default = ""

    def __str__(self):
        if self.default:
            return '{}={}'.format(self.name, self.default)
        return self.name


class Function(_Object):
    """Function of class method

    Has a `.name`, `.docstring` and a list of `.arguments`"""
    def __init__(self):
        _Object.__init__(self)
        self.docstring = None
        self.arguments = list()

    def __str__(self):
        if self.arguments:
            return '{}({})'.format(self.name, ', '.join([str(a) for a in self.arguments]))
        else:
            return self.name + '()'
