# add modules folder to interpreter path
import sys
import os
import json
import prance
from pathlib import Path
from typing import Dict, Any

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

from services.user_service import UserService
from env_info import is_running_locally, get_resources_path

if __name__ == "__main__":
    resources_path = get_resources_path()

    with open(f'{resources_path}/default_users.json', "r") as file_handler:
        content = file_handler.read()
        users = json.loads(content)

        for user in users:
            if "username" in user and "password" in user and "role" in user:
                username = user["username"]
                password = user["password"]
                UserService.add(username, password, role=user["role"])
                print(f"User {username} : {password} created")
            else:
                print(f"Missing field in user object, required=(username, password, role), given=({user.keys()})")