#!python


# -*- coding: utf-8 -*-

from __future__ import print_function, unicode_literals
from PyInquirer import style_from_dict, Token, prompt, Separator
from examples import custom_style_1
from examples import custom_style_2
from examples import custom_style_3
from pprint import pprint
import os, errno
import wget
import urllib.request
import shutil
from pathlib import Path
import subprocess
import datetime
from termcolor import colored


#Custom Made Imports

from custom_imports import Install_server
from custom_imports import Update_server
from custom_imports import Remove_server
from custom_imports import scrape_website

factocli_version = "0.3.3"

factorio_string = """
___________              __               .__         _________ .____    .___ 
\_   _____/____    _____/  |_  ___________|__| ____   \_   ___ \|    |   |   |
 |    __) \__  \ _/ ___\   __\/  _ \_  __ \  |/  _ \  /    \  \/|    |   |   |
 |     \   / __ \\  \___|  | (  <_> )  | \/  (  <_> ) \     \___|    |___|   |
 \___  /  (____  /\___  >__|  \____/|__|  |__|\____/   \______  /_______ \___|
     \/        \/     \/                                      \/        \/    
     """
    


def ask_what_to_do():
    what_to_do_prompt = {
        'type': 'list',
        'name': 'mainoption',
        'message': 'What do you want to do?',
        'choices': [
            Separator(),
            'Install Latest Stable Server',
            'Install Latest Experimental Server', 
            Separator(),
            'Update Existing Server',
            Separator(), 
            'Install Webserver Apache2. Communicates with a TCP Socket (Socket IO)',
            'Install Webserver nGinx. Communicates with a TCP Socket (Socket IO)',
            Separator(),
            'Install HTTP API. For Developers (Uses flask)',
            'Install Android App API. Required for the android app! (SocketIO)',
            Separator(),
            'Remove Existing Server',
            'Remove Webserver Apache2',
            'Remove Webserver nGinx',
            'Remove HTTP API for developers',
            'Remove Android API. Used by the android app',
            Separator()
            ]
    }
    answers = prompt(what_to_do_prompt, style=custom_style_3)
    return answers['mainoption']



def main():
    option = ask_what_to_do()
    if(option == 'Install Latest Experimental Server'):
        Install_server.experimental_server_main()

    if(option == 'Install Latest Stable Server'):
        Install_server.stable_server_main()
        
    if(option == 'Update Existing Server'):
        Update_server.update_main()
    
    if(option == 'Get Installed Server Version'):
        print("Getting the installed server version")
    
    if(option == 'Remove Existing Server'):
        Remove_server.remove_server_main()


def get_date_and_time():
    date_and_time = datetime.datetime.now()
    date_and_time = str(date_and_time)
    date_and_time = date_and_time[0:19]
    return date_and_time



def program_information():
    print(factorio_string)              # Prints the ASCII Art 
    latest_stable_version ,latest_experimental_version = scrape_website.scrape_website_main()
    print(colored("Current Date and Time: ","red") + get_date_and_time())
    print(colored("Latest Factorio Experimental Version: ", "red") + latest_experimental_version)
    print(colored("Latest Factorio Stable Version: ", "red") + latest_stable_version)
    print(colored("Factocli Version: ", "red") + factocli_version)
    print("For more information visit the Github Documentation site: https://github.com/Edris89/facto")
    print("\n")


if __name__ == '__main__':
    program_information()
    main()
