def calculate_block_stats(bam_block, config_id, config_name):
    if (bam_block.get_type() == 'IP6Block'):
        block_address = bam_block.get_property('prefix')
        block = ipaddress.ip_network(block_address)
    else:
        block_address = bam_block.get_property('CIDR')
        block = ipaddress.ip_network(block_address)
    block_data = {}
    block_data_list = []
    if (bam_block.get_type() == 'IP4Block'):
        for network in bam_block.get_ip4_networks():
            return_data = calculate_network_stats(network, config_id, config_name)
            block_data_list.extend(return_data)
        for found_block in bam_block.get_ip4_blocks():
            return_data = calculate_block_stats(found_block, config_id, config_name)
            block_data_list.extend(return_data)
        next_address = bam_block.get_next_available_ip4_address()
        if (next_address != ''):
            block_data.update({'next_available_address': next_address})
        try:
            next_available = bam_block.get_next_available_ip4_network(256, auto_create=False)
            block_data.update({'next_available_network': next_available})
        except APIException as e:
            next_available = ''
    elif (bam_block.get_type() == 'IP6Block'):
        for network in bam_block.get_ip6_networks():
            return_data = calculate_network_stats(network, config_id, config_name)
        for found_block in bam_block.get_ip6_blocks():
            return_data = calculate_block_stats(found_block, config_id, config_name)
    else:
        next_available = ''
    return block_data_list
def calculate_block_stats(bam_block, config_id, config_name):
    if (bam_block.get_type() == 'IP6Block'):
        block_address = bam_block.get_property('prefix')
        block = ipaddress.ip_network(block_address)
    else:
        block_address = bam_block.get_property('CIDR')
        block = ipaddress.ip_network(block_address)
    block_data = {}
    block_data_list = []
    if (bam_block.get_type() == 'IP4Block'):
        for network in bam_block.get_ip4_networks():
            return_data = calculate_network_stats(network, config_id, config_name)
            block_data_list.extend(return_data)
        for found_block in bam_block.get_ip4_blocks():
            return_data = calculate_block_stats(found_block, config_id, config_name)
            block_data_list.extend(return_data)
        next_address = bam_block.get_next_available_ip4_address()
        if (next_address != ):
            block_data.update({'next_available_address': next_address})
        try:
            next_available = bam_block.get_next_available_ip4_network(256, auto_create=False)
            block_data.update({'next_available_network': next_available})
        except APIException as e:
            next_available = 
    elif (bam_block.get_type() == 'IP6Block'):
        for network in bam_block.get_ip6_networks():
            return_data = calculate_network_stats(network, config_id, config_name)
        for found_block in bam_block.get_ip6_blocks():
            return_data = calculate_block_stats(found_block, config_id, config_name)
    else:
        next_available = 
    return block_data_list