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

import com.red.circle.common.business.dto.cmd.app.AppRoomIdCmd;
import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.framework.core.response.CommonErrorCode;
import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManagerService;
import com.red.circle.other.infra.database.mongo.service.live.RoomTouristService;
import com.red.circle.tool.core.sequence.IdWorkerUtils;
import com.red.circle.tool.core.text.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 上传房间足迹.
 *
 * @author pengliang on 2020/12/12
 */
@Component
@RequiredArgsConstructor
public class UploadRoomTouristCmdExe {

  private final RoomTouristService roomTouristService;
  private final RoomProfileManagerService roomProfileManagerService;

  public void execute(AppRoomIdCmd cmd) {

    // 无法操作，错误归属
    ResponseAssert.isTrue(CommonErrorCode.INOPERABLE_WRONG_ATTRIBUTION,
        StringUtils.startsWith(
            roomProfileManagerService.getRoomSysOrigin(cmd.getRoomId()),
            cmd.requireReqSysOrigin()
        )
    );

    roomTouristService.add(cmd.requiredReqUserId(), cmd.getRoomId(), IdWorkerUtils.getId());
  }

}
