package cn.com.ctop.kuaishou.modules.batch.controller;

import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.kuaishou.modules.batch.service.IDelKuaiShouVideoGetService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 */
@Slf4j
@Api(tags = "快手-获取视频接口")
@RestController
@RequestMapping("/del/video")
public class DelKuaiShouVideoGetController {
    @Autowired
    private IDelKuaiShouVideoGetService kuaiShouVideoGetService;


    @GetMapping(value = "/insertVideoList")
    public Result<Object> insertAutoVideo(Long accountId) {
        Result<Object> result = new Result<>();
        try {
            if (Check.isNull(accountId)) {
                result.error500("添加账户");
                return result;
            }
            kuaiShouVideoGetService.insertDelVideoList(accountId);
            result.success("操作成功！");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }

    @GetMapping(value = "/getCreateInfo")
    public Result<Object> getCreateInfo(Long accountId, String photoName) {
        Result<Object> result = new Result<>();
        try {
            if (Check.isNull(accountId) || Check.isNull(photoName)) {
                result.error500("添加账户和素材名");
                return result;
            }
            kuaiShouVideoGetService.getCreateInfo(accountId, photoName);
            result.success("操作成功！");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }


    @GetMapping(value = "/changeCreativesPutStatus")
    public Result<Object> changeCreativesPutStatus(Long accountId) {
        Result<Object> result = new Result<>();
        try {
            if (Check.isNull(accountId)) {
                result.error500("添加账户");
                return result;
            }
            kuaiShouVideoGetService.changeCreativesPutStatus(accountId);
            result.success("操作成功！");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }

    @GetMapping(value = "/deleteAccountVideos")
    public Result<Object> deleteAccountVideos(Long accountId, String photoName) {
        Result<Object> result = new Result<>();
        try {
            if (Check.isNull(accountId) || Check.isNull(photoName)) {
                result.error500("添加账户和素材名");
                return result;
            }
            //1 获取账户下所有视频
            kuaiShouVideoGetService.insertDelVideoList(accountId);
            Thread.sleep(1000l);
            //2 通过【素材名】查询相关视频和关联的创意、程序化创意
            kuaiShouVideoGetService.getCreateInfo(accountId, photoName);
            Thread.sleep(1000l);
            //3 更改创意状态为【删除】，并删除账户下该视频
            kuaiShouVideoGetService.changeCreativesPutStatus(accountId);
            result.success("操作成功！");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }

}
