import Counter from '../models/counter.js'
import Member from '../models/member.js'

export async function assignMemberNumber(memberId) {
  const counter = await Counter.findOneAndUpdate(
    { _id: 'memberNumber' },
    { $inc: { seq: 1 } },
    { new: true, upsert: true }
  )
  await Member.findByIdAndUpdate(memberId, { memberNumber: counter.seq }, { runValidators: false })
  return counter.seq
}
