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

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.modelassessstoplist.vo.*;
import cn.iocoder.yudao.module.llm.dal.dataobject.modelassessstoplist.ModelAssessStoplistDO;
import cn.iocoder.yudao.module.llm.service.modelassessstoplist.ModelAssessStoplistService;

@Tag(name = "管理后台 - 停用词表 定义")
@RestController
@RequestMapping("/llm/model-assess-stoplist")
@Validated
public class ModelAssessStoplistController {

    @Resource
    private ModelAssessStoplistService modelAssessStoplistService;

    @PostMapping("/create")
    @Operation(summary = "创建停用词表 定义")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-stoplist:create')")
    public CommonResult<Long> createModelAssessStoplist(@Valid @RequestBody ModelAssessStoplistSaveReqVO createReqVO) {
        return success(modelAssessStoplistService.createModelAssessStoplist(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新停用词表 定义")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-stoplist:update')")
    public CommonResult<Boolean> updateModelAssessStoplist(@Valid @RequestBody ModelAssessStoplistSaveReqVO updateReqVO) {
        modelAssessStoplistService.updateModelAssessStoplist(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除停用词表 定义")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('llm:model-assess-stoplist:delete')")
    public CommonResult<Boolean> deleteModelAssessStoplist(@RequestParam("id") Long id) {
        modelAssessStoplistService.deleteModelAssessStoplist(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得停用词表 定义")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-stoplist:query')")
    public CommonResult<ModelAssessStoplistRespVO> getModelAssessStoplist(@RequestParam("id") Long id) {
        ModelAssessStoplistDO modelAssessStoplist = modelAssessStoplistService.getModelAssessStoplist(id);
        return success(BeanUtils.toBean(modelAssessStoplist, ModelAssessStoplistRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得停用词表 定义分页")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-stoplist:query')")
    public CommonResult<PageResult<ModelAssessStoplistRespVO>> getModelAssessStoplistPage(@Valid ModelAssessStoplistPageReqVO pageReqVO) {
        PageResult<ModelAssessStoplistDO> pageResult = modelAssessStoplistService.getModelAssessStoplistPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ModelAssessStoplistRespVO.class));
    }

    @GetMapping("/all")
    @Operation(summary = "获得停用词表 定义分页")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-stoplist:query')")
    public CommonResult<List<ModelAssessStoplistRespVO>> getModelAssessStoplistAll() {
       List<ModelAssessStoplistDO> list = modelAssessStoplistService.getModelAssessStoplistAll();
        return success(BeanUtils.toBean(list, ModelAssessStoplistRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出停用词表 定义 Excel")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-stoplist:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportModelAssessStoplistExcel(@Valid ModelAssessStoplistPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ModelAssessStoplistDO> list = modelAssessStoplistService.getModelAssessStoplistPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "停用词表 定义.xls", "数据", ModelAssessStoplistRespVO.class,
                        BeanUtils.toBean(list, ModelAssessStoplistRespVO.class));
    }

}