#!/usr/bin/env python

import argparse
from databeaver import DataBeaver
from databeaver import ConfigFormats


def main():
    """
    Command Line Script for the data_beaver module


    Command Line Usage
        ./fbb.py <action> - General Format

    Responsible For
        1. Parsing Command Line Arguments
        2. Validating the action requested is a valid action
        3. Calling the run() method of the requested action
    :return:
    """
    command_arguments = {'build': [], 'dependencies':[], 'destroy': [], 'create-project': ['--type']}
    # TODO: Get a better tag line
    desc = "DataBeaver - The Data Model Orchestration Tool"
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument('action')
    args = parser.parse_known_args()[0]

    beaver = DataBeaver()

    # Parse the command line again, now with command specific arguments
    if args.action in command_arguments:
        for argument in command_arguments[args.action]:
            parser.add_argument(argument)
        args = parser.parse_known_args()[0]

    if args.action == 'build':
        beaver.build(args)
    elif args.action == 'create-project':
        project_name = input('Enter Project Name: ')
        print("1. ini")
        print("2. json")
        print("3. toml")
        print("4. yaml")
        config_format = ConfigFormats(int(input('Enter the number of the desired config file format: ')))
        beaver.create_project(project_name)
    elif args.action == 'dependencies':
        beaver.model_dependencies(args)
    elif args.action == 'destroy':
        beaver.destroy(args)
    else:
        print(f"{args.action} not defined")


# Base Call
main()
