from input_helpers import ask_user, ask_user_yes_no
from validators import ListValidator, NonEmptyStringValidator
from prompt_toolkit.completion import WordCompleter
from config.efs_config import efs_config
from config.ebs_config import ebs_config


def shared_storage_config():
    shared_storage_list = []

    while True:
        print("\n\nShared storage configuration:\n")
        options = ['Ebs', 'Efs']

        set_next_storage = ask_user_yes_no(
            'Do you want to add a file system to the cluster? (yes/no)[no]: ')

        if not set_next_storage:
            break

        file_system = ask_user(
            question='Pick a file system (TAB to scroll)[Ebs]: ',
            validator=ListValidator(options),
            completer=WordCompleter(options, ignore_case=True),
            default='Ebs'
        )
        volume_name = ask_user(
            question='Name for the volume: ',
            validator=NonEmptyStringValidator()
        )
        mount_dir = ask_user(
            question='Path to mount: ',
            validator=NonEmptyStringValidator()
        )

        if file_system == 'Ebs':
            file_system_settings = ebs_config()
        elif file_system == 'Efs':
            file_system_settings = efs_config()

        shared_storage = {
            "MountDir": mount_dir,
            "Name": volume_name,
            "StorageType": file_system
        }
        shared_storage.update(file_system_settings)

        shared_storage_list.append(shared_storage)

    if shared_storage_config:
        return {
            "SharedStorage": shared_storage_list
        }
    return
