package com.red.circle.other.infra.annotation.aspect;

import com.red.circle.external.inner.endpoint.message.ImAccountClient;
import com.red.circle.external.inner.model.cmd.message.RegisterAccountCmd;
import com.red.circle.mq.rocket.business.producer.UserMqMessageService;
import com.red.circle.other.infra.convertor.user.UserProfileInfraConvertor;
import com.red.circle.other.inner.model.cmd.user.account.CreateAccountCmd;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 注册扩展信息.
 *
 * @author pengliang on 2020/11/5
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class CreateAccountExpandProcess {

  private final ImAccountClient imAccountClient;
  private final UserMqMessageService userMqMessageService;
  private final UserProfileInfraConvertor userProfileInfraConvertor;

  public void process(CreateAccountCmd cmd) {
    userMqMessageService.loginLogger(cmd.requiredReqUserIdStr(), userProfileInfraConvertor.toLoginLoggerEventRegister(cmd));

    // 注册IM
    imAccountClient.register(toRegisterAccountCmd(cmd));
  }

  private RegisterAccountCmd toRegisterAccountCmd(CreateAccountCmd cmd) {
    return new RegisterAccountCmd()
        .setAvatar(cmd.getProfile().getUserAvatar())
        .setIdentifier(cmd.requiredReqUserId())
        .setNickname(cmd.getProfile().getUserNickname())
        .setLang(cmd.getReqLanguage());
  }

}
