import os


def generate_usernames(firstname, lastname):
    firstname = firstname.lower()
    lastname = lastname.lower()

    # Possible username patterns
    patterns = ["{fn}.{ln}", "{ln}.{fn}", "{fn}{ln}", "{ln}{fn}", "{fn}_{ln}", "{ln}_{fn}", "{fn[0]}{ln}",
                "{ln}{fn[0]}", "{fn}", "{ln}", "{fn[0]}.{ln}", "{fn}{ln[0]}"]

    users = []
    for pattern in patterns:
        try:
            username = pattern.format(fn=firstname, ln=lastname)
            users.append(username)
        except Exception:
            pass
    return users


# Example usage
if __name__ == "__main__":

    domain = '@cybercorp.com'
    usernames = []
    USER_LIST = os.path.join(os.path.dirname(os.path.abspath(__file__)), "users.txt")
    
    with open(USER_LIST) as f:
        usernames = f.readlines()
        usernames = [x.strip().replace("\n", "") for x in usernames]

    user_wordlist = []
    for u in usernames:
        firstname, lastname = u.split(" ")
        words = generate_usernames(firstname, lastname)
        user_wordlist.append(words)
        
    # Ensure user_wordlist.txt is saved in the current directory
    output_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "user_wordlist.txt")
    with open(output_path, "w") as f:
        for words in user_wordlist:
            f.writelines(f"{word}{domain}\n" for word in words)
