import re


def getCallConnectionInfo(call, dest, pdmssp=False):
    """
    Method expects call dict input from output from getCallStatusV2() method. Extract call info - RemotePartyNumber, 
        CallState, CallHandle and LineID, from call if dest matches.
    INPUTS: call as dict(body), dest as string
    OUTPUT: Returns response body as dict when dest match successful, None when match unsuccessful.
    """     
    body_dict = {}
    
    if not pdmssp:
        for i in range(len(call["data"])):
            # Removes 'sip:' from RemotePartyNumber if present.
            body_dict["RemotePartyNumber"] = re.sub( "^sip:", "", call["data"][i]["RemotePartyNumber"] )
            if body_dict["RemotePartyNumber"] == dest:
                body_dict["CallState"] = call["data"][i]["CallState"]
                body_dict["CallHandle"] = call["data"][i]["CallHandle"]
                body_dict["LineID"] = call["data"][i]["LineID"]

    elif pdmssp:
        for i in range(len(call["data"]["body"]["data"])):
            # Removes 'sip:' from RemotePartyNumber if present.
            body_dict["RemotePartyNumber"] = re.sub( "^sip:", "", call["data"]["body"]["data"][i]["RemotePartyNumber"] )
            if body_dict["RemotePartyNumber"] == dest:
                body_dict["CallState"] = call["data"]["body"]["data"][i]["CallState"]
                body_dict["CallHandle"] = call["data"]["body"]["data"][i]["CallHandle"]
                body_dict["LineID"] = call["data"]["body"]["data"][i]["LineID"]
    
    return body_dict