package com.red.circle.other.app.command.room;
import com.red.circle.common.business.dto.cmd.app.AppRoomIdCmd;
import com.red.circle.other.app.dto.clientobject.room.RoomSudCo;
import com.red.circle.other.app.dto.cmd.room.UpdateRoomSudCmd;
import com.red.circle.other.infra.database.rds.entity.game.GameRoomSudRecord;
import com.red.circle.other.infra.database.rds.service.game.GameRoomSudRecordService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Objects;


@Service
@AllArgsConstructor
public class RoomSudUserCmdExe {

    private final GameRoomSudRecordService gameRoomSudRecordService;

    public RoomSudCo execute(AppRoomIdCmd cmd){
        GameRoomSudRecord roomSudRecord=gameRoomSudRecordService.getRoomIdSud(cmd.getRoomId());
        if(Objects.isNull(roomSudRecord)){
           return new RoomSudCo();
        }
        RoomSudCo co=new RoomSudCo();
        co.setRoomId(roomSudRecord.getRoomId());
        co.setGameName(roomSudRecord.getGameName());
        co.setGameCode(roomSudRecord.getGameCode());
        co.setCreateUser(roomSudRecord.getCreateUser());
        co.setSysOrigin(roomSudRecord.getSysOrigin());
        co.setGameOrigin(roomSudRecord.getGameOrigin());
       return co;
    }


    public void addRoomSud(UpdateRoomSudCmd cmd){
        gameRoomSudRecordService.dalRoomSudRecord(cmd.getRoomId());
        if(cmd.getOpenSudMode()){
            //开启游戏
            GameRoomSudRecord roomSudRecord=new GameRoomSudRecord();
            roomSudRecord.setGameCode(cmd.getGameCode());
            roomSudRecord.setGameOrigin(cmd.getGameOrigin());
            roomSudRecord.setGameName(cmd.getGameName());
            roomSudRecord.setRoomId(cmd.getRoomId());
            roomSudRecord.setCreateUser(cmd.getReqUserId());
            roomSudRecord.setUpdateUser(cmd.getReqUserId());
            roomSudRecord.setSysOrigin(cmd.getReqSysOrigin().getOrigin());
            gameRoomSudRecordService.save(roomSudRecord);
        }
    }
}
