import { type UserRecord, updateUserRecord } from "db/dbUser";
import type User from "user";

export async function changeBalance(
	user: User,
	userRecord: UserRecord,
	amount: number,
): Promise<false | UserRecord> {
	userRecord.balance = userRecord.balance += amount;
	if (userRecord.balance < 0) return false;
	await updateUserRecord(user, userRecord);
	return userRecord;
}
