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

import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskauto.vo.ModelAssessTaskAutoPageReqVO;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskauto.vo.ModelAssessTaskAutoRespVO;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.manualAnnoVo.ManualModelAnswerPageReqVO;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.vo.ManualAssessmentPageRespVO;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.vo.ManualEvaluationReportRespVO;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.vo.ModelAssessTaskManualRespVO;
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.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.modelassesstaskmanualbackup.vo.*;
import cn.iocoder.yudao.module.llm.dal.dataobject.modelassesstaskmanualbackup.ModelAssessTaskManualBackupDO;
import cn.iocoder.yudao.module.llm.service.modelassesstaskmanualbackup.ModelAssessTaskManualBackupService;

@Tag(name = "管理后台 - 人工评估备份")
@RestController
@RequestMapping("/llm/model-assess-task-manual-backup")
@Validated
public class ModelAssessTaskManualBackupController {

    @Resource
    private ModelAssessTaskManualBackupService modelAssessTaskManualBackupService;

    @PostMapping("/create")
    @Operation(summary = "创建人工评估备份")
//    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-manual-backup:create')")
    public CommonResult<Long> createModelAssessTaskManualBackup(@Valid @RequestBody ModelAssessTaskManualBackupSaveReqVO createReqVO) {
        return success(modelAssessTaskManualBackupService.createModelAssessTaskManualBackup(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新人工评估备份")
//    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-manual-backup:update')")
    public CommonResult<Boolean> updateModelAssessTaskManualBackup(@Valid @RequestBody ModelAssessTaskManualBackupSaveReqVO updateReqVO) {
        modelAssessTaskManualBackupService.updateModelAssessTaskManualBackup(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除人工评估备份")
    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-manual-backup:delete')")
    public CommonResult<Boolean> deleteModelAssessTaskManualBackup(@RequestParam("id") Long id) {
        modelAssessTaskManualBackupService.deleteModelAssessTaskManualBackup(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得人工评估备份")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-manual-backup:query')")
    public CommonResult<ModelAssessTaskManualBackupRespVO> getModelAssessTaskManualBackup(@RequestParam("id") Long id) {
        ModelAssessTaskManualBackupRespVO modelAssessTaskManual = modelAssessTaskManualBackupService.getModelAssessTaskManualBackup1(id);
        return success(modelAssessTaskManual);
    }

    @GetMapping("/page")
    @Operation(summary = "获得人工评估备份分页")
//    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-manual-backup:query')")
    public CommonResult<PageResult<ModelAssessTaskManualBackupRespVO>> getModelAssessTaskManualBackupPage(@Valid ModelAssessTaskManualBackupPageReqVO pageReqVO) {
        PageResult<ModelAssessTaskManualBackupRespVO> pageResult = modelAssessTaskManualBackupService.getModelAssessTaskManualPage1(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/automatic-get")
    @Operation(summary = "模型自动评估备份 —— 备份自动评估")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-auto:query')")
    public CommonResult<ModelAssessTaskAutoRespVO> getModelAssessTaskAuto(@RequestParam("id") Long id) {
        ModelAssessTaskAutoRespVO result = modelAssessTaskManualBackupService.getModelAssessTaskAuto(id);

        return success(result);
    }
    @GetMapping("/automatic-page")
    @Operation(summary = "模型自动评估备份 —— 备份自动评估分页")
//    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-auto:query')")
    public CommonResult<PageResult<ModelAssessTaskAutoRespVO>> getModelAssessTaskAutoPage(@Valid ModelAssessTaskAutoPageReqVO pageReqVO) {
        PageResult<ModelAssessTaskAutoRespVO> pageResult = modelAssessTaskManualBackupService.getModelAssessTaskAutoPage1(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出人工评估备份 Excel")
//    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-manual-backup:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportModelAssessTaskManualBackupExcel(@Valid ManualModelAnswerBackupPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ManualAssessmentPageRespVO> list = modelAssessTaskManualBackupService.getManualAssessment(pageReqVO).getList();
        // 导出 Excel
        ManalExcelExportUtils.write(response, "人工评估备份.xls", "人工评估导出备份", ModelAssessTaskManualBackupRespVO.class,
                list);
    }
    @GetMapping("/gitReport")
    @Operation(summary = "查看报告详情")
//    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-manual:query')")
    public CommonResult<List<ManualEvaluationReportRespVO>> gitViewTheReportDetails(@RequestParam("id") Long id) {
        //TODO 人工评估-查看报告待补充
        List<ManualEvaluationReportRespVO> manualEvaluationReportRespVOS = modelAssessTaskManualBackupService.gitViewTheReportDetails(id);
        return success(manualEvaluationReportRespVOS);
    }

    @GetMapping("/getManualAssessment")
    @Operation(summary = "获取模型结果")
//    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-manual:query')")
    public CommonResult<PageResult<ManualAssessmentPageRespVO>> getManualAssessment(@Valid ManualModelAnswerBackupPageReqVO pageReqVO) {
        return success(modelAssessTaskManualBackupService.getManualAssessment(pageReqVO));
    }

    @GetMapping("/gitManualReport")
    @Operation(summary = "获取模型结果")
//    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-manual:query')")
    public CommonResult<List<String>> queryTheEvaluationType(@Valid ManualModelAnswerPageReqVO pageReqVO) {
        List<String> evaluationTypeList = modelAssessTaskManualBackupService.queryTheEvaluationType(pageReqVO);
        return success(evaluationTypeList);
    }


}

