text: 'use strict';
  
  const Boom = require('@hapi/boom');
  const ListUsers = require('../../application/use_cases/ListUsers');
  const CreateUser = require('../../application/use_cases/CreateUser');
  const GetUser = require('../../application/use_cases/GetUser');
  const DeleteUser = require('../../application/use_cases/DeleteUser');
  
  module.exports = {
  
    async createUser(request) {
  
      // Context
      const serviceLocator = request.server.app.serviceLocator;
  
      // Input
      const { firstName, lastName, email, password } = request.payload;
  
      // Treatment
      const user = await CreateUser(firstName, lastName, email, password, serviceLocator);
  
      // Output
      return serviceLocator.userSerializer.serialize(user);
    },
  
    async findUsers(request) {
  
      // Context
      const serviceLocator = request.server.app.serviceLocator;
  
      // Treatment
      const users = await ListUsers(serviceLocator);
  
      // Output
      return users.map(serviceLocator.userSerializer.serialize)
    },
  
    async getUser(request) {
  
      // Context
      const serviceLocator = request.server.app.serviceLocator;
  
      // Input
      const userId = request.params.id;
  
      // Treatment
      const user = await GetUser(userId, serviceLocator);
  
      // Output
      if (!user) {
        return Boom.notFound();
      }
      return serviceLocator.userSerializer.serialize(user);
    },
  
    async deleteUser(request, h) {
  
      // Context
      const serviceLocator = request.server.app.serviceLocator;
  
      // Input
      const userId = request.params.id;
  
      // Treatment
      await DeleteUser(userId, serviceLocator);
  
      // Output
      return h.response().code(204);
    },
  
  };
  