package com.backendsys.modules.crt.controller;

import com.backendsys.modules.common.aspect.SysLog;
import com.backendsys.modules.common.config.security.utils.SecurityUtil;
import com.backendsys.modules.common.utils.Result;
import com.backendsys.modules.crt.entity.CrtDramaProject;
import com.backendsys.modules.crt.entity.CrtDramaProjectSettings;
import com.backendsys.modules.crt.entity.CrtDramaProjectStoryboard;
import com.backendsys.modules.crt.service.CrtDramaProjectService;
import com.backendsys.modules.crt.service.CrtDramaProjectStoryboardService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
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.*;

@Validated
@RestController
@Tag(name = "短剧创作-项目管理-分镜管理")
public class CrtDramaProjectStoryboardController {

    @Autowired
    private CrtDramaProjectStoryboardService crtDramaProjectStoryboardService;

    @Operation(summary = "获取分集信息/分镜列表")
    @PreAuthorize("@sr.hasPermission('36.2.1')")
    @GetMapping("/api/crt/drama/getStoryboard")
    public Result getStoryboard(@Validated(CrtDramaProjectStoryboard.StoryboardDetail.class) CrtDramaProjectStoryboard crtDramaProjectStoryboard) {
        return Result.success().put("data", crtDramaProjectStoryboardService.selectCrtDramaProjectStoryboardDetail(crtDramaProjectStoryboard));
    }

    @SysLog("创建分集/分镜")
    @Operation(summary = "创建分集/分镜")
    @PreAuthorize("@sr.hasPermission('36.2.2')")
    @PostMapping("/api/crt/drama/initStoryboard")
    public Result initStoryboard(@Validated(CrtDramaProject.InitStoryboard.class) @RequestBody CrtDramaProjectStoryboard crtDramaProjectStoryboard) {
        crtDramaProjectStoryboard.setUser_id(SecurityUtil.getUserId());
        return Result.success().put("data", crtDramaProjectStoryboardService.createStoryboard(crtDramaProjectStoryboard));
    }

    @SysLog("编辑分镜")
    @Operation(summary = "编辑分镜")
    @PutMapping("/api/crt/drama/updateStoryboard")
    public Result updateStoryboard(@Validated(CrtDramaProjectStoryboard.Update.class) @RequestBody CrtDramaProjectStoryboard crtDramaProjectStoryboard) {
        return Result.success().put("data", crtDramaProjectStoryboardService.updateStoryboard(crtDramaProjectStoryboard));
    }

    @SysLog("清空全部分镜 (仅保留一个空分镜)")
    @Operation(summary = "清空全部分镜 (仅保留一个空分镜)")
    @DeleteMapping("/api/crt/drama/clearStoryboard")
    public Result clearStoryboard(@Validated(CrtDramaProjectStoryboard.Clear.class) @RequestBody CrtDramaProjectStoryboard crtDramaProjectStoryboard) {
        return Result.success().put("data", crtDramaProjectStoryboardService.clearStoryboard(crtDramaProjectStoryboard));
    }

    @SysLog("删除分集")
    @Operation(summary = "删除分集")
    @DeleteMapping("/api/crt/drama/deleteStoryboard")
    public Result deleteStoryboard(@Validated(CrtDramaProjectStoryboard.Delete.class) @RequestBody CrtDramaProjectStoryboard crtDramaProjectStoryboard) {
        return Result.success().put("data", crtDramaProjectStoryboardService.deleteStoryboard(crtDramaProjectStoryboard));
    }

    @SysLog("删除单个分镜")
    @Operation(summary = "删除单个分镜")
    @DeleteMapping("/api/crt/drama/deleteStoryboardBySort")
    public Result deleteStoryboardBySort(@Validated(CrtDramaProjectStoryboard.DeleteBySort.class) @RequestBody CrtDramaProjectStoryboard crtDramaProjectStoryboard) {
        return Result.success().put("data", crtDramaProjectStoryboardService.deleteStoryboardBySort(crtDramaProjectStoryboard));
    }

}
