/**
 * Get All Users Query Handler
 * Handles retrieval of all users
 */
class GetAllUsersQueryHandler {
  constructor(prisma) {
    this.prisma = prisma;
  }

  /**
   * Execute get all users query
   * @param {GetAllUsersQuery} query 
   * @returns {Promise<Array>} List of users without passwords
   */
  async handle(query) {
    const users = await this.prisma.user.findMany({
      orderBy: { createdAt: 'desc' }
    });

    // Remove passwords from all users
    return users.map(({ password, ...user }) => user);
  }
}

module.exports = GetAllUsersQueryHandler;
