# TODO: Docstrings

import processes.base
from utilities import get_unix_ifiwconfig_output_field


class IWConfigProcessOutput(object):
    # TODO: Docstrings
    def __init__(self):
        # TODO: Docstrings
        self.ieee_mode = None
        self.essid = None
        self.mode = None
        self.frequency = None
        self.bssid = None


class IWConfigProcess(processes.base.BaseProcess):
    # TODO: Docstrings
    def get_interface_info(self, interface_name):
        # TODO: Docstrings
        output, _ = super().run_process(['iwconfig', interface_name])
        result = IWConfigProcessOutput()

        if 'no wireless extensions' not in output:
            for line in output.split('\n'):
                # IEEE Mode
                if 'IEEE' in line:
                    result.ieee_mode = get_unix_ifiwconfig_output_field(line, 'IEEE')

                # ESSID
                if 'ESSID:' in line:
                    result.essid = get_unix_ifiwconfig_output_field(line.replace('"', ''), 'ESSID:')

                # Wireless Mode
                if 'Mode:' in line:
                    result.mode = get_unix_ifiwconfig_output_field(line, 'Mode:').upper()

                # Frequency
                if 'Frequency' in line:
                    result.frequency = get_unix_ifiwconfig_output_field(line, 'Frequency:')

                # BSSID
                if 'Access Point:' in line:
                    result.bssid = get_unix_ifiwconfig_output_field(line, 'Access Point:')

        return result
