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

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
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.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.llm.controller.admin.prompttemplatestagsbackup.vo.*;
import cn.iocoder.yudao.module.llm.dal.dataobject.prompttemplatestagsbackup.PromptTemplatesTagsBackupDO;
import cn.iocoder.yudao.module.llm.service.prompttemplatestagsbackup.PromptTemplatesTagsBackupService;

@Tag(name = "管理后台 - Prompt 模板标签关系表 备份表，记录模板和标签之间的多对多关系")
@RestController
@RequestMapping("/llm/prompt-templates-tags-backup")
@Validated
public class PromptTemplatesTagsBackupController {

    @Resource
    private PromptTemplatesTagsBackupService promptTemplatesTagsBackupService;

    @PostMapping("/create")
    @Operation(summary = "创建Prompt 模板标签关系表 备份表，记录模板和标签之间的多对多关系")
//    @PreAuthorize("@ss.hasPermission('llm:prompt-templates-tags-backup:create')")
    public CommonResult<Long> createPromptTemplatesTagsBackup(@Valid @RequestBody PromptTemplatesTagsBackupSaveReqVO createReqVO) {
        return success(promptTemplatesTagsBackupService.createPromptTemplatesTagsBackup(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新Prompt 模板标签关系表 备份表，记录模板和标签之间的多对多关系")
//    @PreAuthorize("@ss.hasPermission('llm:prompt-templates-tags-backup:update')")
    public CommonResult<Boolean> updatePromptTemplatesTagsBackup(@Valid @RequestBody PromptTemplatesTagsBackupSaveReqVO updateReqVO) {
        promptTemplatesTagsBackupService.updatePromptTemplatesTagsBackup(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除Prompt 模板标签关系表 备份表，记录模板和标签之间的多对多关系")
    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('llm:prompt-templates-tags-backup:delete')")
    public CommonResult<Boolean> deletePromptTemplatesTagsBackup(@RequestParam("id") Long id) {
        promptTemplatesTagsBackupService.deletePromptTemplatesTagsBackup(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得Prompt 模板标签关系表 备份表，记录模板和标签之间的多对多关系")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('llm:prompt-templates-tags-backup:query')")
    public CommonResult<PromptTemplatesTagsBackupRespVO> getPromptTemplatesTagsBackup(@RequestParam("id") Long id) {
        PromptTemplatesTagsBackupDO promptTemplatesTagsBackup = promptTemplatesTagsBackupService.getPromptTemplatesTagsBackup(id);
        return success(BeanUtils.toBean(promptTemplatesTagsBackup, PromptTemplatesTagsBackupRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得Prompt 模板标签关系表 备份表，记录模板和标签之间的多对多关系分页")
//    @PreAuthorize("@ss.hasPermission('llm:prompt-templates-tags-backup:query')")
    public CommonResult<PageResult<PromptTemplatesTagsBackupRespVO>> getPromptTemplatesTagsBackupPage(@Valid PromptTemplatesTagsBackupPageReqVO pageReqVO) {
        PageResult<PromptTemplatesTagsBackupDO> pageResult = promptTemplatesTagsBackupService.getPromptTemplatesTagsBackupPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, PromptTemplatesTagsBackupRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出Prompt 模板标签关系表 备份表，记录模板和标签之间的多对多关系 Excel")
//    @PreAuthorize("@ss.hasPermission('llm:prompt-templates-tags-backup:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportPromptTemplatesTagsBackupExcel(@Valid PromptTemplatesTagsBackupPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<PromptTemplatesTagsBackupDO> list = promptTemplatesTagsBackupService.getPromptTemplatesTagsBackupPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "Prompt 模板标签关系表 备份表，记录模板和标签之间的多对多关系.xls", "数据", PromptTemplatesTagsBackupRespVO.class,
                        BeanUtils.toBean(list, PromptTemplatesTagsBackupRespVO.class));
    }

}
