import json
async def open_account(user):
    users = await get_bank_data()

    if str(user.id) in users:
        return False
    else:
        users[str(user.id)] = {}
        users[str(user.id)]["wallet"] = 0
        users[str(user.id)]["bank"] = 250

    with open("data/bank.json", "w") as f:
        json.dump(users, f, indent=4)
    return True


async def get_bank_data():
    with open("data/bank.json", "r") as f:
        users = json.load(f)

    return users


async def update_bank(user, change=0, mode="wallet"):
    users = await get_bank_data()

    users[str(user.id)][mode] += change

    with open("data/bank.json", "w") as f:
        json.dump(users, f, indent=4)
    bal = [users[str(user.id)]["wallet"], users[str(user.id)]["bank"]]
    return bal
