const { PrismaClient } = require("@prisma/client")
const prisma = new PrismaClient()

async function listUserBadges(userId, options = {}) {
  return prisma.userBadge.findMany({
    where: { userId },
    orderBy: options.orderBy || { earnedAt: "desc" },
    select: options.select || undefined,
    include: options.include || undefined,
  })
}

async function createUserBadge(data, options = {}) {
  return prisma.userBadge.create({
    data,
    select: options.select || undefined,
  })
}

async function deleteUserBadge(where, options = {}) {
  return prisma.userBadge.delete({
    where,
    select: options.select || undefined,
  })
}

module.exports = {
  listUserBadges,
  createUserBadge,
  deleteUserBadge,
}
