"""
"""

import phantom.rules as phantom
import json
from datetime import datetime, timedelta
def on_start(container):
    phantom.debug('on_start() called')
    
    # call 'check_peer_list' block
    check_peer_list(container=container)

    return

def check_peer_list(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
    phantom.debug('check_peer_list() called')
    
    id_value = container.get('id', None)

    check_peer_list__peer_list = None

    ################################################################################
    ## Custom Code Start
    ################################################################################

    # Write your custom code here...

    phantom.debug(id_value)
    peer_list_name = phantom.get_container(container['id'])['data']["peer_list"]
    phantom.debug(peer_list_name)  
    peer_list = phantom.get_list(peer_list_name)[2]
    # phantom.debug(peer_list)
    outputs = {'peer_list': peer_list}    

    ################################################################################
    ## Custom Code End
    ################################################################################

    phantom.save_run_data(key='check_peer_list:peer_list', value=json.dumps(check_peer_list__peer_list))
    cf_local_filter_peer_list_by_priority_1(container=container)

    return

def cf_local_filter_peer_list_by_priority_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
    phantom.debug('cf_local_filter_peer_list_by_priority_1() called')
    
    container_property_0 = [
        [
            container.get("id"),
        ],
    ]
    literal_values_0 = [
        [
            "critical, high",
        ],
    ]

    parameters = []

    literal_values_0_0 = [item[0] for item in literal_values_0]

    for item0 in container_property_0:
        parameters.append({
            'container': item0[0],
            'filter_items': literal_values_0_0,
        })
    ################################################################################
    ## Custom Code Start
    ################################################################################

    # Write your custom code here...

    ################################################################################
    ## Custom Code End
    ################################################################################    

    # call custom function "local/filter_peer_list_by_priority", returns the custom_function_run_id
    phantom.custom_function(custom_function='local/filter_peer_list_by_priority', parameters=parameters, name='cf_local_filter_peer_list_by_priority_1', callback=cf_local_Create_Containers_From_List_1)

    return

def cf_local_Create_Containers_From_List_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
    phantom.debug('cf_local_Create_Containers_From_List_1() called')
    
    custom_function_result_0 = phantom.collect2(container=container, datapath=['cf_local_filter_peer_list_by_priority_1:custom_function_result.data.filtered_list'], action_results=results )
    container_property_0 = [
        [
            container.get("label"),
        ],
    ]

    parameters = []

    custom_function_result_0_0 = [item[0] for item in custom_function_result_0]

    for item0 in container_property_0:
        parameters.append({
            'mylist': custom_function_result_0_0,
            'container_label': item0[0],
        })
    ################################################################################
    ## Custom Code Start
    ################################################################################

    # Write your custom code here...

    ################################################################################
    ## Custom Code End
    ################################################################################    

    # call custom function "local/Create_Containers_From_List", returns the custom_function_run_id
    phantom.custom_function(custom_function='local/Create_Containers_From_List', parameters=parameters, name='cf_local_Create_Containers_From_List_1')

    return

def on_finish(container, summary):
    phantom.debug('on_finish() called')
    # This function is called after all actions are completed.
    # summary of all the action and/or all details of actions
    # can be collected here.

    # summary_json = phantom.get_summary()
    # if 'result' in summary_json:
        # for action_result in summary_json['result']:
            # if 'action_run_id' in action_result:
                # action_results = phantom.get_action_results(action_run_id=action_result['action_run_id'], result_data=False, flatten=False)
                # phantom.debug(action_results)

    return