class DocumentRepository {
  constructor(prisma) { this.prisma = prisma; }
  findByUserId(userId) { return this.prisma.document.findMany({ where: { userId } }); }
  findByUserAndType(userId, type) { return this.prisma.document.findUnique({ where: { userId_documentType: { userId, documentType: type } } }); }
  findById(id) { return this.prisma.document.findUnique({ where: { id }, include: { user: { include: { profile: true } } } }); }
  create(data) { return this.prisma.document.create({ data }); }
  delete(id) { return this.prisma.document.delete({ where: { id } }); }
  listAll(filters) {
    const where = {};
    if (filters.type) where.documentType = filters.type;
    if (filters.verified !== undefined) where.isVerified = filters.verified;
    if (filters.search) {
      where.user = { is: { profile: { fullName: { contains: filters.search } } } };
    }
    return this.prisma.document.findMany({
      where,
      include: { user: { include: { profile: true } } },
      orderBy: { createdAt: 'desc' },
      skip: (filters.page - 1) * filters.limit,
      take: filters.limit,
    });
  }
  count(filters) {
    const where = {};
    if (filters.type) where.documentType = filters.type;
    if (filters.verified !== undefined) where.isVerified = filters.verified;
    if (filters.search) where.user = { is: { profile: { fullName: { contains: filters.search } } } };
    return this.prisma.document.count({ where });
  }
}

export default DocumentRepository;
