from blends.models import (
    NId,
)
from blends.syntax.builders.method_declaration import (
    DirectChildren,
    build_method_declaration_node,
)
from blends.syntax.models import (
    SyntaxGraphArgs,
)


def reader(args: SyntaxGraphArgs) -> NId:
    graph = args.ast_graph
    name = "AnonymousMethod"

    block_id = graph.nodes[args.n_id].get("label_field_body")
    parameters_id = graph.nodes[args.n_id].get("label_field_parameters")

    direct: DirectChildren = {}
    if block_id:
        direct["block_id"] = block_id
    if parameters_id is not None:
        direct["parameters_id"] = parameters_id

    return build_method_declaration_node(args, name, direct, {})
