import type { WarningDashboard, WarningListQuery } from '@nexumi/shared';
import { prisma } from '../prisma';

export async function listWarnings(guildId: string, query: WarningListQuery): Promise<WarningDashboard[]> {
  const warnings = await prisma.warning.findMany({
    where: {
      guildId,
      ...(query.userId ? { userId: query.userId } : {})
    },
    orderBy: { createdAt: 'desc' },
    take: 100
  });

  return warnings.map((warning) => ({
    id: warning.id,
    userId: warning.userId,
    moderatorId: warning.moderatorId,
    reason: warning.reason,
    caseId: warning.caseId,
    createdAt: warning.createdAt.toISOString()
  }));
}
