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

import cn.iocoder.yudao.module.llm.controller.admin.dataset.vo.DatasetAnswerPageReqVO;
import cn.iocoder.yudao.module.llm.controller.admin.dataset.vo.DatasetAnswerRespVO;
import cn.iocoder.yudao.module.llm.controller.admin.dataset.vo.DatasetAnswerSaveReqVO;
import cn.iocoder.yudao.module.llm.dal.dataobject.dataset.DatasetAnswerDO;
import cn.iocoder.yudao.module.llm.service.dataset.DatasetAnswerService;
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/dataset-answer")
@Validated*/
public class DatasetAnswerController {

    @Resource
    private DatasetAnswerService datasetAnswerService;

    @PostMapping("/create")
    @Operation(summary = "创建数据集数据问题标注内容")
    @PreAuthorize("@ss.hasPermission('llm:dataset-answer:create')")
    public CommonResult<Long> createDatasetAnswer(@Valid @RequestBody DatasetAnswerSaveReqVO createReqVO) {
        return success(datasetAnswerService.createDatasetAnswer(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新数据集数据问题标注内容")
    @PreAuthorize("@ss.hasPermission('llm:dataset-answer:update')")
    public CommonResult<Boolean> updateDatasetAnswer(@Valid @RequestBody DatasetAnswerSaveReqVO updateReqVO) {
        datasetAnswerService.updateDatasetAnswer(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除数据集数据问题标注内容")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('llm:dataset-answer:delete')")
    public CommonResult<Boolean> deleteDatasetAnswer(@RequestParam("id") Long id) {
        datasetAnswerService.deleteDatasetAnswer(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得数据集数据问题标注内容")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('llm:dataset-answer:query')")
    public CommonResult<DatasetAnswerRespVO> getDatasetAnswer(@RequestParam("id") Long id) {
        DatasetAnswerDO datasetAnswer = datasetAnswerService.getDatasetAnswer(id);
        return success(BeanUtils.toBean(datasetAnswer, DatasetAnswerRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得数据集数据问题标注内容分页")
    @PreAuthorize("@ss.hasPermission('llm:dataset-answer:query')")
    public CommonResult<PageResult<DatasetAnswerRespVO>> getDatasetAnswerPage(@Valid DatasetAnswerPageReqVO pageReqVO) {
        PageResult<DatasetAnswerDO> pageResult = datasetAnswerService.getDatasetAnswerPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DatasetAnswerRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出数据集数据问题标注内容 Excel")
    @PreAuthorize("@ss.hasPermission('llm:dataset-answer:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDatasetAnswerExcel(@Valid DatasetAnswerPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DatasetAnswerDO> list = datasetAnswerService.getDatasetAnswerPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "数据集数据问题标注内容.xls", "数据", DatasetAnswerRespVO.class,
                        BeanUtils.toBean(list, DatasetAnswerRespVO.class));
    }

}