package controller;

import dto.jivoprofile.JivoProfileDto;
import org.hsqldb.lib.StringUtil;
import org.springframework.web.bind.annotation.*;

import ru.cg.webbpm.modules.security.api.model.User;
import ru.cg.webbpm.modules.security.api.service.UserService;

@RestController
public class ProfileController {

  private UserService userService;

  public ProfileController(UserService userService) {
    this.userService = userService;
  }

  @RequestMapping(value = "/profile/jivo/{userId}", method = RequestMethod.GET)
  public JivoProfileDto profile(@PathVariable("userId") String userId) {

    if (StringUtil.isEmpty(userId)) {
      return new JivoProfileDto();
    }

    User user = userService.get(userId);

    JivoProfileDto profileDto = new JivoProfileDto();
    profileDto.setUsername(user.firstName());
    profileDto.setEmail(user.email());
    profileDto.setPhone(user.phone());
    return profileDto;
  }
}
