/**
 * Update User Profile Command Handler
 * Handles user profile update logic
 */
class UpdateUserProfileCommandHandler {
  constructor(prisma) {
    this.prisma = prisma;
  }

  /**
   * Execute update profile command
   * @param {UpdateUserProfileCommand} command 
   * @returns {Promise<Object>} Updated user data
   */
  async handle(command) {
    const { userId, name } = command;

    if (!name) {
      throw new Error('Name is required');
    }

    const user = await this.prisma.user.update({
      where: { id: userId },
      data: { name }
    });

    const { password, ...userWithoutPassword } = user;
    return userWithoutPassword;
  }
}

module.exports = UpdateUserProfileCommandHandler;
