package com.backendsys.modules.crt.controller;

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.service.CrtDramaProjectService;
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 CrtDramaProjectController {

    @Autowired
    private CrtDramaProjectService crtDramaProjectService;

    @Operation(summary = "项目列表 (全权限)")
    @PreAuthorize("@sr.hasPermission('36.1.1')")
    @GetMapping("/api/crt/drama/getDramaProjectAllList")
    public Result getDramaProjectAllList(@Validated CrtDramaProject crtDramaProject) {
        return Result.success().put("data", crtDramaProjectService.selectCrtDramaProjectList(crtDramaProject));
    }

    @Operation(summary = "项目列表 (我的)")
    @PreAuthorize("@sr.hasPermissions(T(java.util.Arrays).asList('36.1.1', '36.1.2'), T(com.backendsys.modules.common.enums.MatchType).OR)")
    @GetMapping("/api/crt/drama/getDramaProjectList")
    public Result getDramaProjectList(@Validated CrtDramaProject crtDramaProject) {
        crtDramaProject.setUser_id(SecurityUtil.getUserId());
        return Result.success().put("data", crtDramaProjectService.selectCrtDramaProjectList(crtDramaProject));
    }

    @Operation(summary = "创建项目")
    @PreAuthorize("@sr.hasPermission('36.1.2')")
    @PostMapping("/api/crt/drama/createDramaProject")
    public Result createDramaProject(@Validated(CrtDramaProject.Create.class) @RequestBody CrtDramaProject crtDramaProject) {
        Long user_id = SecurityUtil.getUserId();
        crtDramaProject.setUser_id(user_id);
        crtDramaProject.setCreate_user_id(user_id);
        return Result.success().put("data", crtDramaProjectService.createCrtDramaProject(crtDramaProject));
    }

    @Operation(summary = "编辑项目")
    @PutMapping("/api/crt/drama/updateDramaProject")
    public Result updateDramaProject(@Validated(CrtDramaProject.Update.class) @RequestBody CrtDramaProject crtDramaProject) {
        return Result.success().put("data", crtDramaProjectService.updateCrtDramaProject(crtDramaProject));
    }

    @Operation(summary = "编辑项目生图/生视频配置")
    @PutMapping("/api/crt/drama/updateDramaProjectSettings")
    public Result updateStoryboardSettings(@Validated(CrtDramaProjectSettings.UpdateSettings.class) @RequestBody CrtDramaProjectSettings crtDramaProjectSettings) {
        return Result.success().put("data", crtDramaProjectService.updateDramaProjectSettings(crtDramaProjectSettings));
    }

    @Operation(summary = "删除项目")
    @DeleteMapping("/api/crt/drama/deleteDramaProject")
    public Result deleteDramaProject(@Validated(CrtDramaProject.Delete.class) @RequestBody CrtDramaProject crtDramaProject) {
        return Result.success().put("data", crtDramaProjectService.deleteCrtDramaProject(crtDramaProject));
    }

}
