import { LocaleSchema, type Locale } from '@nexumi/shared';
import type { PrismaClient } from '@prisma/client';
import { env } from './env.js';

export async function getGuildLocale(
  prisma: PrismaClient,
  guildId: string | null
): Promise<Locale> {
  if (!guildId) {
    return env.DEFAULT_LOCALE;
  }
  const settings = await prisma.guildSettings.findUnique({
    where: { guildId },
    select: { locale: true }
  });
  const parsed = LocaleSchema.safeParse(settings?.locale);
  return parsed.success ? parsed.data : env.DEFAULT_LOCALE;
}
