from collections import namedtuple

MailConfig = namedtuple('MailConfig', 'server port secure username password email')


class config:
    portal_dir = 'C:\\GAPS\\Portal'
    tasks_dir = portal_dir + '\\Tasks'
    xml_dir = tasks_dir + '\\config'
    log_dir = tasks_dir + '\\logs'
    cognos_dir = 'C:\\Program Files (x86)\\Cognos\\cer5\\bin'
    tools_dir = 'C:\\Projekte\\Python\\gctools'
    kunde = 'Test'
    versand_separat = False

    def __init__(self):
        cfg = {}
        with open(self.tasks_dir + '\\GAPS.ini', 'r') as stream:
            for line in stream.readlines():
                if '=' in line:
                    key, value = line.split('=')
                    cfg[key] = value.replace('"', '').replace('\n', '')
        self.kunde = cfg.get('KUNDE', 'Test')

        self.smtp = MailConfig(**{
            'server': 'smtp.ionos.de',
            'port': '465',
            'secure': 'ssl',
            'username': 'versand@global-cube.de',
            'password': 'gc01smtp',
            'email': 'versand@global-cube.de'
        })
        if 'SMTP_HOST' in cfg and cfg['SMTP_HOST'] != '':
            secure = {'': '', 'N': '', 'J': 'ssl', 'SSL': 'ssl', 'TLS': 'tls'}

            self.smtp = MailConfig(**{
                'server': cfg.get('SMTP_HOST'),
                'port': cfg.get('SMTP_PORT'),
                'secure': secure[cfg.get('SMTP_SSL', '')],
                'username': cfg.get('SMTP_USER'),
                'password': cfg.get('SMTP_PW'),
                'email': cfg.get('SMTP_FROM'),
            })
        if 'VERSAND_SEPARAT' in cfg:
            self.versand_separat = cfg['VERSAND_SEPARAT'] == 'J'
