// Shared team members list - used by both middleware and auth utilities
export const TEAM_MEMBERS = new Set([
  // Email addresses
  "sarthak.saga@gmail.com",
  "sarthak@codeflash.ai",
  "team@codeflash.ai",
  "saurabh@codeflash.ai",
  "hesham@codeflash.ai",
  "aseem@codeflash.ai",
  "ali@codeflash.ai",
  "turcioskevinr@gmail.com",
  "misra.saurabh1@gmail.com",
  "ashraf@codeflash.ai",
  // GitHub usernames (Auth0 nickname field)
  "saga4",
  "misrasaurabh1",
  "mashraf-222",
  "krrt7",
  "aseembits93",
  "mohammedahmed18",
  "heshamhm28",
])

export function isTeamMemberCheck(user: { email?: string; nickname?: string }): boolean {
  const email = user.email?.toLowerCase()
  const nickname = user.nickname?.toLowerCase()
  return (
    (email !== undefined && TEAM_MEMBERS.has(email)) ||
    (nickname !== undefined && TEAM_MEMBERS.has(nickname))
  )
}

/** Codeflash team members OR anyone with an @unstructured.io email */
export function isMembenchAllowed(user: { email?: string; nickname?: string }): boolean {
  if (isTeamMemberCheck(user)) return true
  const email = user.email?.toLowerCase()
  return email !== undefined && email.endsWith("@unstructured.io")
}
