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

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.manualAnnoVo.ManualModelAnswerPageReqVO;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.manualAnnoVo.ManualModelAnswerSaveReqVO;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.vo.ManualAssessmentPageRespVO;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.vo.ModelAssessTaskManualPageReqVO;
import cn.iocoder.yudao.module.llm.service.modelassesstaskmanual.ManualModelAnswerService;
import cn.iocoder.yudao.module.llm.utils.ManalExcelExportUtils;
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.Operation;

import javax.servlet.http.HttpServletResponse;
import javax.validation.*;
import java.io.IOException;
import java.util.*;

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

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 模型评估人工标注 模型回答")
@RestController
@RequestMapping("/llm/manual-model-answer")
@Validated
public class ManualModelAnswerController {

    @Resource
    private ManualModelAnswerService manualModelAnswerService;

    @GetMapping("/getManualAssessment")
    @Operation(summary = "获取列表")
//    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-manual:query')")
    public CommonResult<PageResult<ManualAssessmentPageRespVO>> getManualAssessment(@Valid ManualModelAnswerPageReqVO pageReqVO) {
        //TODO 人工评估-人工评估标注补充
        return success(manualModelAnswerService.getManualAssessment(pageReqVO));
    }
    @PostMapping("/anno")
    @Operation(summary = "人工标注")
//    @PreAuthorize("@ss.hasPermission('llm:manual-model-answer:update')")
    public CommonResult<Boolean> annoManualModelAnswer(@Valid @RequestBody List<ManualModelAnswerSaveReqVO> reqRespVos){
        manualModelAnswerService.annoManualModelAnswer(reqRespVos);
        return success(true);
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出模型评估人工标注 模型回答 Excel")
//    @PreAuthorize("@ss.hasPermission('llm:manual-model-answer:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportManualModelAnswerExcel(@Valid ManualModelAnswerPageReqVO pageReqVO,
                                             HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ManualAssessmentPageRespVO> list = manualModelAnswerService.getManualAssessment(pageReqVO).getList();
        // 导出 Excel
        ManalExcelExportUtils.write(response, "模型评估人工标注 模型回答.xls", "数据",ManualAssessmentPageRespVO.class,list);
    }
/*    @PostMapping("/create")
    @Operation(summary = "创建模型评估人工标注 模型回答")
    @PreAuthorize("@ss.hasPermission('llm:manual-model-answer:create')")
    public CommonResult<Long> createManualModelAnswer(@Valid @RequestBody ManualModelAnswerSaveReqVO createReqVO) {
        return success(manualModelAnswerService.createManualModelAnswer(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新模型评估人工标注 模型回答")
    @PreAuthorize("@ss.hasPermission('llm:manual-model-answer:update')")
    public CommonResult<Boolean> updateManualModelAnswer(@Valid @RequestBody ManualModelAnswerSaveReqVO updateReqVO) {
        manualModelAnswerService.updateManualModelAnswer(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除模型评估人工标注 模型回答")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('llm:manual-model-answer:delete')")
    public CommonResult<Boolean> deleteManualModelAnswer(@RequestParam("id") Long id) {
        manualModelAnswerService.deleteManualModelAnswer(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得模型评估人工标注 模型回答")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('llm:manual-model-answer:query')")
    public CommonResult<ManualModelAnswerRespVO> getManualModelAnswer(@RequestParam("id") Long id) {
        ManualModelAnswerDO manualModelAnswer = manualModelAnswerService.getManualModelAnswer(id);
        return success(BeanUtils.toBean(manualModelAnswer, ManualModelAnswerRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得模型评估人工标注 模型回答分页")
    @PreAuthorize("@ss.hasPermission('llm:manual-model-answer:query')")
    public CommonResult<PageResult<ManualModelAnswerRespVO>> getManualModelAnswerPage(@Valid ManualModelAnswerPageReqVO pageReqVO) {
        PageResult<ManualModelAnswerDO> pageResult = manualModelAnswerService.getManualModelAnswerPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ManualModelAnswerRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出模型评估人工标注 模型回答 Excel")
    @PreAuthorize("@ss.hasPermission('llm:manual-model-answer:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportManualModelAnswerExcel(@Valid ManualModelAnswerPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ManualModelAnswerDO> list = manualModelAnswerService.getManualModelAnswerPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "模型评估人工标注 模型回答.xls", "数据", ManualModelAnswerRespVO.class,
                        BeanUtils.toBean(list, ManualModelAnswerRespVO.class));
    }*/

}