package com.gic.haoban.manage.web.controller.video;

import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.clerk.api.dto.ClerkDTO;
import com.gic.cloudimage.api.dto.CloudVideoDTO;
import com.gic.cloudimage.api.dto.account.VideoGroupInfoDTO;
import com.gic.cloudimage.api.qdto.CloudVideoQDTO;
import com.gic.cloudimage.api.service.CloudVideoApiService;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.PageHelperUtils;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.haoban.manage.web.controller.content.adaptor.ClerkStoreAdaptor;
import com.gic.haoban.manage.web.qo.video.DeleteVideoQo;
import com.gic.haoban.manage.web.qo.video.VideoGroupQo;
import com.gic.haoban.manage.web.qo.video.VideoListQo;
import com.gic.haoban.manage.web.vo.video.CloudVideoGroupVo;
import com.gic.haoban.manage.web.vo.video.CloudVideoInfoVo;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 好办-视频号-视频空间分组
 * @Author MUSI
 * @Date 2023/10/30 9:08 AM
 * @Description
 * @Version
 **/
@RestController
@RequestMapping(path = "/cloud/video")
public class CloudVideoController {

    @Autowired
    private CloudVideoApiService cloudVideoApiService;

    @Autowired
    private ClerkStoreAdaptor clerkStoreAdaptor;

    /**
     * 视频空间-分组列表
     * @param videoGroupQo
     * @return
     */
    @RequestMapping(path = "/group/list")
    public RestResponse<List<CloudVideoGroupVo>> queryVideoGroupList(VideoGroupQo videoGroupQo) {

        ServiceResponse<List<VideoGroupInfoDTO>> serviceResponse =
                cloudVideoApiService.queryVideoGroupList(videoGroupQo.getEnterpriseId(), null, videoGroupQo.getSearch());
        if (!serviceResponse.isSuccess() || CollectionUtils.isEmpty(serviceResponse.getResult())) {
            return RestResponse.successResult();
        }
        List<CloudVideoGroupVo> cloudVideoGroupVos = EntityUtil.changeEntityListByJSON(CloudVideoGroupVo.class, serviceResponse.getResult());
        return RestResponse.successResult(cloudVideoGroupVos);
    }

    /**
     * 视频列表(剪辑记录列表)
     * @param videoListQo
     * @return
     */
    @RequestMapping(path = "/list")
    public RestResponse<Page<CloudVideoInfoVo>> queryVideoList(VideoListQo videoListQo) {

        ClerkDTO clerkDTO = clerkStoreAdaptor.queryClerkInfo(videoListQo.getEnterpriseId(), videoListQo.getClerkId());
        if (clerkDTO == null) {
            return RestResponse.successResult();
        }
        CloudVideoQDTO cloudVideoQDTO = new CloudVideoQDTO();
        cloudVideoQDTO.setEnterpriseId(videoListQo.getEnterpriseId());
        cloudVideoQDTO.setPageNum(videoListQo.getPageNum());
        cloudVideoQDTO.setPageSize(videoListQo.getPageSize());
        cloudVideoQDTO.setUserCode(clerkDTO.getClerkCode());
        cloudVideoQDTO.setShowFlag(1);
        // 正常状态的
        cloudVideoQDTO.setStatus(1);
        ServiceResponse<Page<CloudVideoDTO>> serviceResponse = cloudVideoApiService.queryCloudVideoList(cloudVideoQDTO);
        if (!serviceResponse.isSuccess() || serviceResponse.getResult() == null) {
            return RestResponse.successResult();
        }
        Page<CloudVideoInfoVo> cloudVideoInfoVoPage = PageHelperUtils.changePageToCurrentPage(serviceResponse.getResult(), CloudVideoInfoVo.class);
        return RestResponse.successResult(cloudVideoInfoVoPage);
    }

    /**
     * 删除视频 （删除剪辑记录）
     * @param deleteVideoQo
     * @return
     */
    @RequestMapping(path = "/delete")
    public RestResponse<?> deleteVideoInfo(DeleteVideoQo deleteVideoQo) {
        cloudVideoApiService.updateCloudVideShowFlag(deleteVideoQo.getEnterpriseId(), deleteVideoQo.getVideoId(), 0);
        return RestResponse.successResult();
    }
}
