import networkx as nx
import uuid


def generate_nx_graph_from_dfg(dfg, start_activities, end_activities, activities_count):
    """
    Generate a NetworkX graph for reachability-checking purposes out of the DFG

    Parameters
    --------------
    dfg
        DFG
    start_activities
        Start activities
    end_activities
        End activities
    activities_count
        Activities of the DFG along with their count

    Returns
    --------------
    G
        NetworkX digraph
    start_node
        Identifier of the start node (connected to all the start activities)
    end_node
        Identifier of the end node (connected to all the end activities)
    """
    start_node = str(uuid.uuid4())
    end_node = str(uuid.uuid4())
    G = nx.DiGraph()
    G.add_node(start_node)
    G.add_node(end_node)
    for act in activities_count:
        G.add_node(act)
    for edge in dfg:
        G.add_edge(edge[0], edge[1])
    for act in start_activities:
        G.add_edge(start_node, act)
    for act in end_activities:
        G.add_edge(act, end_node)
    return G, start_node, end_node