from os.path import isfile, join

initd_path = "/etc/init.d"
sysd_path = "/etc/systemd/system"

if isfile(join(initd_path, 'cpanel')) or isfile(join(sysd_path, 'cpanel.service')):
    CONTROLPANEL = 'cP'
elif isfile(join(initd_path, 'directadmin')) or isfile(join(sysd_path, 'directadmin.service')):
    CONTROLPANEL = 'DA'
elif isfile(join(initd_path, 'psa')):
    CONTROLPANEL = 'PSA'
else:
    CONTROLPANEL = 'NA'


class SimpleService(object):
    """
    Prototype of Service class.
    Implemented basic functionality to run jobs by `python.d.plugin`
    """

    name = 'SimpleService'
    CONTROLPANEL = CONTROLPANEL

    def __init__(self):
        """
        :param name: <str>
        """
        self.daemon = True
        self.order = list()
        self.definitions = dict()

        self.module_name = self.__module__

    def __repr__(self):
        return '<{cls_bases}: {name}>'.format(cls_bases=', '.join(c.__name__ for c in self.__class__.__bases__),
                                              name=self.name)

    def check(self):
        """
        check() prototype
        :return: boolean
        """
        # self.debug("job doesn't implement check() method. Using default which simply invokes get_data().")
        data = self.get_data()
        if data and isinstance(data, dict):
            return True
        # self.debug('returned value is wrong: {0}'.format(data))
        return False

    def get_data(self):
        return self._get_data()

    def _get_data(self):
        raise NotImplementedError
