import platform
import xbmc
from quasar.logger import log
from quasar.osarch import PLATFORM
from quasar.addon import ADDON_NAME, ADDON


def notify(message='', header=None, time=5000, image=''):
    if header is None:
        header = ADDON_NAME
    return xbmc.executebuiltin('Notification("%s", "%s", "%d", "%s")' %
                               (toUtf8(header), toUtf8(message), toUtf8(time), toUtf8(image)))

def getLocalizedLabel(label):
    try:
        return ADDON.getLocalizedString(int(label[9:-1])).encode('utf-8', 'ignore')
    except:
        return label

def getLocalizedString(stringId):
    try:
        return ADDON.getLocalizedString(stringId).encode('utf-8', 'ignore')
    except:
        return stringId

def toUtf8(string):
    if isinstance(string, unicode):
        return string.encode('utf-8', 'ignore')
    return string

def system_information():
    build = xbmc.getInfoLabel("System.BuildVersion")
    log.info("System information: %(os)s_%(arch)s %(version)s" % PLATFORM)
    log.info("Kodi build version: %s" % build)
    log.info("OS type: %s" % platform.system())
    log.info("uname: %s" % repr(platform.uname()))
    return PLATFORM
