from pathlib import Path
import json


def create_file(bot, key: str, default, wipe: bool = False):
    """
    Creates a JSON config file for all guilds it can see with a default
        Parameters:
            bot (discord.Bot): Reference to the bot so it can get the guilds
            key (str): The `guild_key.json` to generate
            default (any): The value to put in as a placeholder
            wipe (bool): Wipe the files forcefully
        Returns:
            Success (bool): Did it succeed
    """
    if Path(f'./data/guild_{key}.json').is_file() and not wipe: # allows for wiping of the config
        return False

    data = {}

    for guild in bot.guilds:
        _guild = str(guild.id)
        data[_guild] = default

    with open(f'./data/guild_{key}.json', 'w') as fileout:
        json.dump(data, fileout, indent=4)
    return True