import sys
import os
from pathlib import Path
from typing import Dict, Any
import requests

modules_path = '../../../modules/'
if os.path.exists(modules_path):
    sys.path.insert(1, modules_path)

import network_constants as nc
from security.token_manager import TokenManager

import tables.add_bank_app as add_bank_app


def add_use_case(use_case: str):
    jwt = TokenManager.getInstance().getToken()
    url = f"https://articonf1.itec.aau.at:30420/api/use-cases"
    response = requests.post(
            url,
            verify=False, 
            proxies = { "http":None, "https":None },
            headers = { "Authorization": f"Bearer {jwt}"},
            json = {"name": use_case}
        )
    
    if response.status_code >= 400:
        raise Exception(f"Error while uploading {use_case}: {str(response.content)}")
    
    print(url+": "+str(response.status_code))
        

if __name__ == "__main__":    
    # disable ssl warnings :) 
    requests.packages.urllib3.disable_warnings() 

    use_case_name = 'bank-app'
    add_use_case(use_case_name)
    add_bank_app.main(use_case_name)