import toml
import logging


def _parse_conf(conf_file: str):
    """Parses the incoming toml config file"""
    try:
        conf = toml.load(conf_file)
    except Exception as e:
        logging.warning(f"Failed to decode TOML file: {e}. Using chrome as browser.")
        return "chrome", "", "", "", ""
    else:
        sid = ''
        token = ''
        to = ''
        from_ = ''

        if 'twilio' in conf:
            if 'auth' in conf['twilio']:
                sid = conf['twilio']['auth']['sid']
                token = conf['twilio']['auth']['token']
            if 'phone' in conf['twilio']:
                to = conf['twilio']['phone']['to']
                from_ = conf['twilio']['phone']['from']

        browser = conf['conf']['browser']
        if 'refresh_mins' in conf:
            refresh_mins = conf['conf']['refresh_mins']
        else:
            refresh_mins = 60

        return browser, refresh_mins, sid, token, to, from_