package com.cool.store.service.impl;

import com.cool.store.dto.trtc.callback.VideoCallBackDTO;
import com.cool.store.mapper.HyPartnerInterviewMapper;
import com.cool.store.request.TRTCVideoCallBackReq;
import com.cool.store.service.TRTCVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TRTCVideoServiceImpl implements TRTCVideoService {

    @Autowired
    private HyPartnerInterviewMapper interviewMapper;

    /**
     * 音视频上传成功后的回调处理
     */
//    @Override
//    public void handleVideoCallBack(TRTCVideoCallBackReq req) {
//        //将视频播放地址拼接到对应的面试信息字段中
//        String videoUrl = req.getEventInfo().getPayLoad().getTencentVod().getVideoUrl();
//        String roomId = req.getEventInfo().getRoomId();
//        interviewMapper.addVideoUrl(roomId, videoUrl);
//    }

    @Override
    public void handleVideoCallBack(VideoCallBackDTO videoCallBackDTO) {
        //防重
        Boolean hasVideoUrl = interviewMapper.hasVideoUrls(videoCallBackDTO.getEventInfo().getPayload().getTencentVod().getVideoUrl());
        if (hasVideoUrl) {
            return;
        }
        //将视频播放地址拼接到对应的面试信息字段中
        String videoUrl = videoCallBackDTO.getEventInfo().getPayload().getTencentVod().getVideoUrl();
        String roomId = videoCallBackDTO.getEventInfo().getRoomId();
        interviewMapper.addVideoUrl(roomId, videoUrl);
    }
}
