from typing import Union


def olt_value_str_to_str(value:str, field_id:int) -> Union[str, int]:
    """ convert value str in show oltqinq-domain to str value

    Args:
        value (str): 要处理的值
        field_id (int): 字段类型ID
    
    Returns:
        str or int: 处理后的值
    """
    # 1(Dst Mac)						00 00 00 00 00 00 00 00
    # 2(Src Mac)						00 00 00 00 00 00 00 00
    # 3(Ethernet Type)				    [ff ff] 00 00 00 00 00 00
    # 4(Vlan4)						    [ff ff] 00 00 00 00 00 00
    # 5(Vlan3)						    [ff ff] 00 00 00 00 00 00
    # 6(Vlan2)						    [ff ff] 00 00 00 00 00 00
    # 7(Vlan1)						    [ff ff] 00 00 00 00 00 00
    # 8(TOS)							[ff] 00 00 00 00 00 00 00
    # 10(TTL)							[ff] 00 00 00 00 00 00 00
    # 11(Protocol Type)				    [ff] 00 00 00 00 00 00 00
    # 12(Src IPv4)					    192.168.1.1
    # 13(Src IPv6)					    1:2:3:4:5:6:7:8
    # 14(Dst IPv4)					    192.168.1.1
    # 15(Dst IPv6)					    1:2:3:4:5:6:7:8
    # 16(L4 Src Port)					[ff ff] 00 00 00 00 00 00
    # 17(L4 Dst Port)					[ff ff] 00 00 00 00 00 00
    # 18(Cos4)						    [ff] 00 00 00 00 00 00 00
    # 19(Cos3)						    [ff] 00 00 00 00 00 00 00
    # 20(Cos2)						    [ff] 00 00 00 00 00 00 00
    # 21(Cos1)						    [ff] 00 00 00 00 00 00 00
    # 22(Dst IPv6 Prefix)				1:2:3:4:5:6:7:8
    # 23(Src IPv6 Prefix)				1:2:3:4:5:6:7:8
    # 24(IP Version)					[ff ff] 00 00 00 00 00 00
    # 25(IPv6 Traffic Class)			[ff] 00 00 00 00 00 00 00
    # 26(IPv6 Flow Label)				[ff ff] 00 00 00 00 00 00
    # 27(IPv6 Next Header)			    [ff] 00 00 00 00 00 00 00

    if field_id in [1, 2]:
        return value.replace(' ', '')[:-4]

    if field_id in [12, 13, 14, 15, 22, 23]:
        return value

    if field_id in [3, 4, 5, 6, 7, 8, 10, 11, 16, 17, 18, 19, 20, 21, 24, 25, 26, 27]:
        strList = value.split(' ')
        # remove '00' in the head until meet no '00'
        while len(strList) != 0 and '00' == strList[0]:
            del strList[0]
        # remove '00' in the tail until meet no '00'
        while len(strList) != 0 and '00' == strList[-1]:
            del strList[-1]
        
        value = ''.join(strList)
        # if value is zero, strValue will be empty string, so we need put 0 here to avoid exception
        if value == '':
            value = '0'
        
        # return
        return int(value, 16)
    
    assert False, "unknown field id: %s" % field_id