import { prisma } from '../config/database';

export const activityRepository = {
  async log(data: {
    userId?: number | null;
    description: string;
    status?: string | null;
  }) {
    return prisma.activity.create({
      data: {
        userId: data.userId ?? null,
        description: data.description,
        status: data.status ?? null,
      },
    });
  },

  async list(filters?: { userId?: number; limit?: number }) {
    return prisma.activity.findMany({
      where: filters?.userId ? { userId: filters.userId } : {},
      take: filters?.limit ?? 50,
      orderBy: { createdAt: 'desc' },
    });
  },

  async count() {
    return prisma.activity.count();
  },
};
