from input_helpers import ask_user
from wrapper.ec2_wrapper import EC2Wrapper
from validators import ListValidator
from prompt_toolkit.completion import WordCompleter

ec2 = EC2Wrapper()


def network_config(region):

    vpcs = ec2.get_vpc_subnets(region)
    vpcs_list = list(vpcs.keys())
    vpc = ask_user(
        question=f'Pick a VPC from available in this region (TAB to scroll)[{vpcs_list[0]}]: ',
        validator=ListValidator(vpcs_list),
        completer=WordCompleter(vpcs_list, ignore_case=True),
        default=vpcs_list[0]
    )

    subnets_list = vpcs[vpc]
    print(subnets_list)
    subnet = ask_user(
        question=f'Pick a subnet from VPC (TAB to scroll)[{subnets_list[0]}]: ',
        validator=ListValidator(subnets_list),
        completer=WordCompleter(subnets_list, ignore_case=True),
        default=subnets_list[0]
    )

    return subnet
