package com.red.circle.other.app.command.room.query;

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.mq.business.model.event.task.TaskApprovalEvent;
import com.red.circle.mq.rocket.business.producer.TaskMqMessage;
import com.red.circle.other.app.convertor.live.RoomProfileAppConvertor;
import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManagerService;
import com.red.circle.other.infra.database.rds.entity.sys.SysCountryCode;
import com.red.circle.other.infra.database.rds.service.sys.SysCountryCodeService;
import com.red.circle.other.inner.model.dto.live.RoomProfileManagerDTO;
import java.util.Objects;

import com.red.circle.tool.core.date.LocalDateTimeUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;


/**
 * 获取我的房间资料信息.
 *
 * @author houyong on 2020/12/10
 */
@Component
@RequiredArgsConstructor
public class RoomVoiceProfileByUserIdQryExe {

  private final SysCountryCodeService sysCountryCodeService;
  private final RoomProfileAppConvertor roomProfileAppConvertor;
  private final RoomProfileManagerService roomProfileManagerService;
  private final TaskMqMessage taskMqMessage;

  public RoomProfileManagerDTO execute(AppExtCommand cmd) {
    RoomProfileManagerDTO roomProfileManagerDTO = roomProfileAppConvertor.toRoomProfileManagerDTO(
        roomProfileManagerService.getByUserId(cmd.requiredReqUserId()));
    if (Objects.nonNull(roomProfileManagerDTO)&&Objects.nonNull(roomProfileManagerDTO.getCountryCode())) {
      //放一个创建自己房间钩子
      taskMqMessage.sendTask(TaskApprovalEvent.builder()
              .taskId(5)
              .userId(cmd.getReqUserId())
              .build());


      SysCountryCode sysCountryCode = sysCountryCodeService.getByCode(roomProfileManagerDTO.getCountryCode());
      roomProfileManagerDTO.setNationalFlag(sysCountryCode.getNationalFlag());
    }
    return roomProfileManagerDTO;
  }

}
