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

async function listBadges(options = {}) {
  return prisma.badge.findMany({
    where: options.where || undefined,
    orderBy: options.orderBy || { name: "asc" },
    select: options.select || undefined,
  })
}

async function findBadge(where, options = {}) {
  return prisma.badge.findUnique({
    where,
    select: options.select || undefined,
  })
}

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

async function updateBadge(where, data, options = {}) {
  return prisma.badge.update({
    where,
    data,
    select: options.select || undefined,
  })
}

module.exports = {
  listBadges,
  findBadge,
  createBadge,
  updateBadge,
}
