package com.backendsys.controller.Ai;

import com.backendsys.aspect.HttpRequestAspect;
import com.backendsys.entity.Ai.AiGenerateVideoDTO;
import com.backendsys.entity.PageDTO;
import com.backendsys.modules.common.config.security.annotations.Anonymous;
import com.backendsys.service.Ai.AiGenerateVideoService;
import com.backendsys.utils.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AiGenerateVideoController {

    @Autowired
    private HttpRequestAspect httpRequestAspect;

    @Autowired
    private AiGenerateVideoService aiGenerateVideoService;

    /**
     * 定制成片
     */
//    @PreAuthorize("@sr.hasPermission('34')")
    @Anonymous
    @PostMapping("/api/ai/generate/video/make")
    public Result makePersonvideo(@Validated(AiGenerateVideoDTO.Create.class) @RequestBody AiGenerateVideoDTO aiGenerateVideoDTO) {

        // [查询] 自身 UserId
        Long user_id = httpRequestAspect.getUserId();
        aiGenerateVideoDTO.setUser_id(user_id);

        return Result.success(aiGenerateVideoService.makeGenerateVideoAndInsert(aiGenerateVideoDTO));
    }

    /**
     * 查询成片任务进度/结果
     */
//    @PreAuthorize("@sr.hasPermission('34')")
    @Anonymous
    @GetMapping("/api/ai/generate/video/getProgress")
    public Result getGenerateVideoProgress(@Validated(AiGenerateVideoDTO.Detail.class) @RequestBody AiGenerateVideoDTO aiGenerateVideoDTO) {

        // [查询] 自身 UserId
        Long user_id = httpRequestAspect.getUserId();
        aiGenerateVideoDTO.setUser_id(user_id);

        Long job_id = aiGenerateVideoDTO.getJob_id();
        return Result.success(aiGenerateVideoService.getGenerateVideoProgressAndUpdate(job_id, user_id));
    }

    /**
     * 获得全部配音列表
     */
//    @PreAuthorize("@sr.hasPermission('34')")
    @Anonymous
    @GetMapping("/api/ai/generate/video/getGenerateVideoTimbre")
    public Result getGenerateVideoTimbre() {
        return Result.success(aiGenerateVideoService.getGenerateVideoTimbre());
    }

    /**
     * 我的成片任务列表
     */
//    @PreAuthorize("@sr.hasPermission('34')")
    @Anonymous
    @GetMapping("/api/ai/generate/video/my/list")
    public Result getGenerateVideoMyList(@Validated PageDTO pageDTO, @Validated AiGenerateVideoDTO aiGenerateVideoDTO) {

        // [查询] 自身 UserId
        Long user_id = httpRequestAspect.getUserId();
        aiGenerateVideoDTO.setUser_id(user_id);

        return Result.success(aiGenerateVideoService.queryAiGenerateVideoList(pageDTO.getPage_num(), pageDTO.getPage_size(), aiGenerateVideoDTO));
    }

    /**
     * 我的成片任务详情
     */
//    @PreAuthorize("@sr.hasPermission('34')")
    @Anonymous
    @GetMapping("/api/ai/generate/video/my/detail")
    public Result getGenerateVideoMyList(@Validated(AiGenerateVideoDTO.Detail.class) AiGenerateVideoDTO aiGenerateVideoDTO) {

        // [查询] 自身 UserId
        Long user_id = httpRequestAspect.getUserId();
        aiGenerateVideoDTO.setUser_id(user_id);

        return Result.success(aiGenerateVideoService.queryAiGenerateVideoDetail(aiGenerateVideoDTO));
    }

}
