package com.ycwl.basic.controller.mobile;

import com.ycwl.basic.annotation.IgnoreLogReq;
import com.ycwl.basic.model.jwt.JwtInfo;
import com.ycwl.basic.model.mobile.goods.VideoTaskReq;
import com.ycwl.basic.model.mobile.goods.VideoTaskStatusVO;
import com.ycwl.basic.service.mobile.GoodsService;
import com.ycwl.basic.service.task.TaskService;
import com.ycwl.basic.utils.ApiResponse;
import com.ycwl.basic.utils.JwtTokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/mobile/task/v1")
public class AppTaskController {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private TaskService taskService;

    @GetMapping("/face/{faceId}")
    @IgnoreLogReq
    public ApiResponse<VideoTaskStatusVO> getTaskStatusByFaceId(@PathVariable("faceId") Long faceId) {
        return ApiResponse.success(goodsService.getTaskStatusByFaceId(faceId));
    }
    @GetMapping("/scenic/{scenicId}")
    @IgnoreLogReq
    public ApiResponse<VideoTaskStatusVO> getAllTaskStatusByScenicId(@PathVariable("scenicId") Long scenicId) {
        JwtInfo worker = JwtTokenUtil.getWorker();
        VideoTaskStatusVO taskStatus = goodsService.getTaskStatusByScenicId(worker.getUserId(), scenicId);
        taskStatus.setScenicId(scenicId);
        return ApiResponse.success(taskStatus);
    }

    /**
     * 查询用户当前景区的具体模版视频合成任务状态
     *
     * @param templateId 模版id
     * @return 1 合成中 2 合成成功
     */
    // 查询用户当前景区的具体模版视频合成任务状态 1 合成中 2 合成成功
    @GetMapping("/face/{faceId}/template/{templateId}")
    @IgnoreLogReq
    public ApiResponse<VideoTaskStatusVO> getTemplateTaskStatus(@PathVariable("faceId") Long faceId, @PathVariable("templateId") Long templateId) {
        return ApiResponse.success(goodsService.getTaskStatusByTemplateId(faceId, templateId));
    }

    @PostMapping("/submit")
    public ApiResponse<String> submitVideoTask(@RequestBody VideoTaskReq videoTaskReq) {
        taskService.createTaskByFaceIdAndTemplateId(videoTaskReq.getFaceId(),videoTaskReq.getTemplateId(),false);
        return ApiResponse.success("成功");
    }
}
