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

import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskauto.vo.ModelAssessTaskStoplistPageReqVO;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskauto.vo.ModelAssessTaskStoplistRespVO;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskauto.vo.ModelAssessTaskStoplistSaveReqVO;
import cn.iocoder.yudao.module.llm.dal.dataobject.modelassesstaskauto.ModelAssessTaskStoplistDO;
import cn.iocoder.yudao.module.llm.service.modelassesstaskauto.ModelAssessTaskStoplistService;
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.*;


/*@Tag(name = "管理后台 - 模型评估任务 —— 自动评估 ——停用词")
@RestController
@RequestMapping("/llm/model-assess-task-stoplist")*/
@Validated
public class ModelAssessTaskStoplistController {

    @Resource
    private ModelAssessTaskStoplistService modelAssessTaskStoplistService;

    @PostMapping("/create")
    @Operation(summary = "创建模型评估任务 —— 自动评估 ——停用词")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-stoplist:create')")
    public CommonResult<Long> createModelAssessTaskStoplist(@Valid @RequestBody ModelAssessTaskStoplistSaveReqVO createReqVO) {
        return success(modelAssessTaskStoplistService.createModelAssessTaskStoplist(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新模型评估任务 —— 自动评估 ——停用词")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-stoplist:update')")
    public CommonResult<Boolean> updateModelAssessTaskStoplist(@Valid @RequestBody ModelAssessTaskStoplistSaveReqVO updateReqVO) {
        modelAssessTaskStoplistService.updateModelAssessTaskStoplist(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除模型评估任务 —— 自动评估 ——停用词")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-stoplist:delete')")
    public CommonResult<Boolean> deleteModelAssessTaskStoplist(@RequestParam("id") Long id) {
        modelAssessTaskStoplistService.deleteModelAssessTaskStoplist(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得模型评估任务 —— 自动评估 ——停用词")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-stoplist:query')")
    public CommonResult<ModelAssessTaskStoplistRespVO> getModelAssessTaskStoplist(@RequestParam("id") Long id) {
        ModelAssessTaskStoplistDO modelAssessTaskStoplist = modelAssessTaskStoplistService.getModelAssessTaskStoplist(id);
        return success(BeanUtils.toBean(modelAssessTaskStoplist, ModelAssessTaskStoplistRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得模型评估任务 —— 自动评估 ——停用词分页")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-stoplist:query')")
    public CommonResult<PageResult<ModelAssessTaskStoplistRespVO>> getModelAssessTaskStoplistPage(@Valid ModelAssessTaskStoplistPageReqVO pageReqVO) {
        PageResult<ModelAssessTaskStoplistDO> pageResult = modelAssessTaskStoplistService.getModelAssessTaskStoplistPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ModelAssessTaskStoplistRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出模型评估任务 —— 自动评估 ——停用词 Excel")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-stoplist:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportModelAssessTaskStoplistExcel(@Valid ModelAssessTaskStoplistPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ModelAssessTaskStoplistDO> list = modelAssessTaskStoplistService.getModelAssessTaskStoplistPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "模型评估任务 —— 自动评估 ——停用词.xls", "数据", ModelAssessTaskStoplistRespVO.class,
                        BeanUtils.toBean(list, ModelAssessTaskStoplistRespVO.class));
    }

}