package cn.iocoder.yudao.module.llm.controller.admin.prompttemplatesbackup;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.module.llm.controller.admin.prompttemplatesbackup.vo.*;
import cn.iocoder.yudao.module.llm.service.prompttemplatesbackup.PromptTemplatesBackupService;

@Tag(name = "管理后台 - Prompt模板备份")
@RestController
@RequestMapping("/llm/prompt-templates-backup")
@Validated
public class PromptTemplatesBackupController {

    @Resource
    private PromptTemplatesBackupService promptTemplatesBackupService;

    @PostMapping("/create")
    @Operation(summary = "创建Prompt模板备份")
//    @PreAuthorize("@ss.hasPermission('llm:prompt-templates-backup:create')")
    public CommonResult<Long> createPromptTemplatesBackup(@Valid @RequestBody PromptTemplatesBackupSaveReqVO createReqVO) {
        return success(promptTemplatesBackupService.createPromptTemplatesBackup(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新Prompt模板备份")
//    @PreAuthorize("@ss.hasPermission('llm:prompt-templates-backup:update')")
    public CommonResult<Boolean> updatePromptTemplatesBackup(@Valid @RequestBody PromptTemplatesBackupSaveReqVO updateReqVO) {
        promptTemplatesBackupService.updatePromptTemplatesBackup(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除Prompt模板备份")
    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('llm:prompt-templates-backup:delete')")
    public CommonResult<Boolean> deletePromptTemplatesBackup(@RequestParam("id") Long id) {
        promptTemplatesBackupService.deletePromptTemplatesBackup(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得Prompt模板备份")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('llm:prompt-templates-backup:query')")
    public CommonResult<PromptTemplatesBackupRespVO> getPromptTemplatesBackup(@RequestParam("id") Long id) {
        return success(promptTemplatesBackupService.getPromptTemplatesBackup(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得Prompt模板备份分页")
//    @PreAuthorize("@ss.hasPermission('llm:prompt-templates-backup:query')")
    public CommonResult<PageResult<PromptTemplatesBackupRespVO>> getPromptTemplatesBackupPage(@Valid PromptTemplatesBackupPageReqVO pageReqVO) {
        return success(promptTemplatesBackupService.getPromptTemplatesBackupPage(pageReqVO));
    }

    @PostMapping("/unbackup")
    @Operation(summary = "取消备份Prompt模板")
//    @PreAuthorize("@ss.hasPermission('llm:prompt-templates-backup:delete')")
    public CommonResult<Boolean> unbackupPromptTemplates(@Valid @RequestBody PromptTemplatesBackupSaveReqVO updateReqVO) {
        promptTemplatesBackupService.unbackupPromptTemplates(updateReqVO);
        return success(true);
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出Prompt模板备份 Excel")
//    @PreAuthorize("@ss.hasPermission('llm:prompt-templates-backup:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportPromptTemplatesBackupExcel(@Valid PromptTemplatesBackupPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<PromptTemplatesBackupDO> list = promptTemplatesBackupService.getPromptTemplatesBackupPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "Prompt模板备份.xls", "数据", PromptTemplatesBackupRespVO.class,
//                        BeanUtils.toBean(list, PromptTemplatesBackupRespVO.class));
//    }

}
