package com.fdkankan.ucenter.service.impl;

import com.fdkankan.common.exception.BusinessException;
import com.fdkankan.ucenter.common.ResultData;
import com.fdkankan.ucenter.httpClient.client.TakeLookClient;
import com.fdkankan.ucenter.httpClient.param.FdRoomAddParam;
import com.fdkankan.ucenter.httpClient.param.FdRoomVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class TakeLookService {

    @Autowired
    TakeLookClient takeLookClient;

    public ResultData<FdRoomVo> fdCreateTakeLookRoom(String roomTitle, List<String> numList, String roomId,String token) {
        FdRoomAddParam param = new FdRoomAddParam();
        param.setRoomTitle(roomTitle);
        param.setNumList(numList);
        param.setRoomId(roomId);
        param.setMaxMan(30);
        param.setPlatform("ucenter");
        return takeLookClient.roomAddOrUpdate(param,token);
    }
    public FdRoomVo getRoomIdByNum(String num,String title,String token) {
        ResultData<FdRoomVo> response = takeLookClient.getRoomIdByNum(num, token);
        if(response.getCode() !=0){
            ResultData<FdRoomVo> fdRoomAddParamResultData = fdCreateTakeLookRoom(title, Arrays.asList(num), null, token);
            if(fdRoomAddParamResultData.getCode() !=0){
                throw new BusinessException(fdRoomAddParamResultData.getCode(),fdRoomAddParamResultData.getMessage());
            }
            return fdRoomAddParamResultData.getData();
        }else {
            return response.getData();
        }

    }

    public void openRoom(String roomId,String token) {

         takeLookClient.openRoom(roomId, token);
    }

}
