const prisma = require("../../db/client")
const { ensureCounterAtLeast, nextId } = require("./idGenerator.service")
const SELLER_ID_KEY = "ids:seller"

async function ensureSellerIdCounter() {
  const latest = await prisma.seller.findFirst({
    select: { id: true },
    orderBy: { id: "desc" },
  })
  const maxId = latest?.id ?? 0
  await ensureCounterAtLeast(SELLER_ID_KEY, maxId)
}

async function generateSellerId() {
  return nextId(SELLER_ID_KEY)
}

module.exports = { ensureSellerIdCounter, generateSellerId }
