import { PrismaService } from '@core/database/prisma/prisma.service';

export async function getUsernameById(
  prisma: PrismaService,
  userId: string | null | undefined,
): Promise<{ username: string; displayName: string | null }> {
  if (!userId) {
    return { username: 'Anonymous', displayName: 'Anonymous User' };
  }
  const user = await prisma.user.findUnique({
    where: { id: userId },
    select: { username: true, displayName: true },
  });
  return {
    username: user?.username || 'Unknown',
    displayName: user?.displayName || null,
  };
}

export function isAfterHours(when: Date | null | undefined): boolean {
  if (!when) return false;
  const hour = when.getUTCHours();
  const day = when.getUTCDay();
  return hour >= 18 || hour < 8 || day === 0 || day === 6;
}
