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

import com.red.circle.common.business.dto.cmd.RoomIdCmd;
import com.red.circle.common.business.dto.cmd.app.AppRoomIdCmd;
import com.red.circle.external.inner.endpoint.message.ImGroupClient;
import com.red.circle.external.inner.model.cmd.message.CreateGroupCmd;
import com.red.circle.other.app.service.room.RoomProfileService;
import com.red.circle.other.infra.database.mongo.entity.live.RoomProfile;
import com.red.circle.other.inner.model.dto.live.RoomProfileManagerDTO;
import java.util.Objects;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author longli on  2024/3/20
 */

@Service
@AllArgsConstructor
public class ImGroupQryExe {

  private final RoomProfileService roomProfileService;

  private final ImGroupClient imGroupClient;

  public Boolean execute(AppRoomIdCmd cmd) {
    RoomProfileManagerDTO roomProfileManagerDTO = roomProfileService.getRoomProfile(cmd);
    Boolean isSuccess = imGroupClient.createAVChatRoomGroup(new CreateGroupCmd()
        .setOwnerAccount(Objects.toString(roomProfileManagerDTO.getUserId()))
        .setGroupId(roomProfileManagerDTO.getRoomAccount())
        .setFaceUrl(roomProfileManagerDTO.getRoomCover())
        .setName(roomProfileManagerDTO.getRoomName())
    ).getBody();
    return isSuccess;
  }

  public Boolean executeTest(AppRoomIdCmd cmd) {
    Boolean isSuccess = imGroupClient.createAVChatRoomGroup(new CreateGroupCmd()
            .setOwnerAccount(Objects.toString(cmd.getRoomId()))
            .setGroupId(Objects.toString(cmd.getRoomId()))
            .setFaceUrl("https://dev.file.momooline.com/160fbc10-b7ea-4a98-9a5d-ac95a520e2.png")
            .setName("")
    ).getBody();
    return isSuccess;
  }

}
