# I moved all the requirements into requirements.txt.
# you can install everything with pip install -r requirements.txt while you're in the directory

import sys
import time

import test_module

import user_module

import utilities_script as utility
import config as config

import credentials

import threading

testModule_: test_module.Test_Module
userModule_: user_module.User_Module

credentials_manager: credentials.Credentials_Module

def main(inputArg):
    args = utility.get_args(inputArg)


def test_module_init(dbCert, Empty):
    print("-init [TEST Module]")
    #testModule_.dbCredential = dbCert
    testModule_.main()

def user_module_init(dbCert, Empty):
    print("-init [USER Module]")
    userModule_.dbCredential = dbCert
    userModule_.main()

def thread_main():
    if utility.isRunningInDocker() == True:
        print("<[DOCKER Detected]>")
    if not config.skip_splashScreen:
        utility.splashScreen()
    global credentials_manager
    global testModule_
    global userModule_

    credentials_manager = credentials.Credentials_Module()

    testModule_ = test_module.Test_Module()
    userModule_ = user_module.User_Module()

    credentials_manager.load_credentials()
    dbCert: credentials.DB_Credential = credentials_manager.find_Credential(credentials.DB_Credential, config.credentialsNickname)

    threads = []
    if config.test_module == True:
        thread_ = threading.Thread(target=test_module_init, args=(dbCert, None))
        thread_.daemon = True
        threads.append(thread_)
        thread_.start()

    if config.user_module == True:
        if utility.isRunningInDocker() == False:
            config.user_module = False
            thread_ = threading.Thread(target=user_module_init, args=(dbCert, None))
            thread_.daemon = True
            threads.append(thread_)
            thread_.start()

    print("---Post Thread Creation Test---\n")
    for t in threads:
        t.join()

    print("---Point of no return---")
    if utility.isRunningInDocker() == False:
        input()



if __name__ == "__main__":
    thread_main()
