import re


def parse_show_ip_ospf_interface(raw_result):
    """
    Parse the 'show ip ospf interface' command raw output.

    :param str raw_result: vtysh raw result string.
    :rtype: dict
    :return: The parsed result of the show ip ospf interface command in a \
        dictionary of the form:

     ::

        {
           'router_id': '2.2.2.2',
           'wait_time': '40',
           'Area_id': '0.0.0.1',
           'hello_timer': '10',
           'Backup_designated_router': '10.10.10.1',
           'hello_due_time': '7.717s',
           'retransmit_time': '5',
           'neighbor_count': '1',
           'state': '<DR >',
           'Interface_id': '1',
           'priority': '1',
           'BDR_Interface_address': '10.10.10.1',
           'bandwidth': '1000',
           'cost': '10',
           'Adjacent_neigbhor_count': '1',
           'internet_address': '10.10.10.2/24',
           'Designated_router': '10.10.10.1',
           'dead_timer': '40',
           'network_type': '<BROADCAST>',
           'transmit_delay': '1',
           'DR_Interface_address': '10.10.10.1'
        }
    """

    show_ip_ospf_int_re = (
        r'\s*Interface (?P<Interface_id>\d+[-.]?\d*[.]?\d*) BW\s*'
        '(?P<bandwidth>\d+) Mbps.*'
        r'\s*Internet address (?P<internet_address>[0-255.]+\S+)\s*'
        'Area (?P<Area_id>[0-255.]+).*'
        r'\s*Router ID\s*:\s*(?P<router_id>[\S]+),\s*Network Type\s*'
        '(?P<network_type>[\S]+),\s*Cost:\s*(?P<cost>\d+).*'
        r'\s*Transmit Delay is (?P<transmit_delay>\d) sec, State\s*'
        '(?P<state>\S+\s*\S+), Priority (?P<priority>\d+).*'
        r'\s*Designated\s*Router\s*\(ID\)\s*'
        '(?P<Designated_router>[\S]+),\s*Interface Address\s*'
        '(?P<DR_Interface_address>[\S]+).*')

    show_ip_ospf_int_re1 = (
        r'\s*Hello (?P<hello_timer>\d+) Dead (?P<dead_timer>\d+) '
        'wait (?P<wait_time>\d+) Retransmit '
        '(?P<retransmit_time>\d+).*'
        r'\s*Hello due in\s*(?P<hello_due_time>\S+).*'
        r'\Neighbor Count is\s*(?P<neighbor_count>\d),\s*Adjacent '
        'neighbor count is\s*(?P<Adjacent_neigbhor_count>\d)'
    )

    bdr_re = (
        r'\s*Backup Designated Router \(ID\) '
        '(?P<Backup_designated_router>[0-255.]+),\s*Interface '
        'Address (?P<BDR_Interface_address>[0-255.]+).*'
    )

    error_no_record = (
        r'No\s*backup\s*designated\.*')

    result = {}

    re_result = re.search(show_ip_ospf_int_re, raw_result, re.DOTALL)
    if (re_result):
        result = re_result.groupdict()

    re_result = re.search(show_ip_ospf_int_re1, raw_result, re.DOTALL)
    if (re_result):
        result1 = re_result.groupdict()
        result.update(result1)

    re_result = re.search(error_no_record, raw_result, re.DOTALL)
    if (re_result):
        return result

    re_result = re.search(bdr_re, raw_result, re.DOTALL)
    if (re_result):
        result1 = re_result.groupdict()
        result.update(result1)

    return result