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

import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.vo.ModelAssessTaskManualPageReqVO;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.vo.ModelAssessTaskManualRespVO;
import cn.iocoder.yudao.module.llm.dal.dataobject.modelassesstaskauto.ModelAssessTaskStoplistDO;
import cn.iocoder.yudao.module.llm.dal.mysql.modelassesstaskauto.ModelAssessTaskStoplistMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.modelassesstaskauto.vo.*;
import cn.iocoder.yudao.module.llm.dal.dataobject.modelassesstaskauto.ModelAssessTaskAutoDO;
import cn.iocoder.yudao.module.llm.service.modelassesstaskauto.ModelAssessTaskAutoService;

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

    @Resource
    private ModelAssessTaskAutoService modelAssessTaskAutoService;
    @Resource
    private ModelAssessTaskStoplistMapper modelingTaskStoplistMapper;

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

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

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

    @GetMapping("/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 = modelAssessTaskAutoService.getModelAssessTaskAuto(id);

        return success(result);
    }

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

    @GetMapping("/export-excel")
    @Operation(summary = "导出模型评估任务 —— 自动评估 Excel")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-auto:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportModelAssessTaskAutoExcel(@Valid ModelAssessTaskAutoPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ModelAssessTaskAutoDO> list = modelAssessTaskAutoService.getModelAssessTaskAutoPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "模型评估任务 —— 自动评估.xls", "数据", ModelAssessTaskAutoRespVO.class,
                        BeanUtils.toBean(list, ModelAssessTaskAutoRespVO.class));
    }

    @GetMapping("/gitReport")
    @Operation(summary = "查看报告详情")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-manual:query')")
    public CommonResult<PageResult<ModelAssessTaskManualRespVO>> gitViewTheReportDetails(@Valid ModelAssessTaskManualPageReqVO pageReqVO) {
        //TODO 自动评估-查看报告待补充
        return success(new PageResult<>());
    }

    @PostMapping("/backedUp")
    @Operation(summary = "备份")
    public void backedUp(ModelAssessTaskManualPageReqVO pageReqVO) {
        //TODO 自动评估-备份待补充
    }

    @PostMapping("/cancelTheBackUp")
    @Operation(summary = "取消备份")
    public void cancelTheBackUp(ModelAssessTaskManualPageReqVO pageReqVO) {
        //TODO 自动评估-取消备份待补充
    }

    @PostMapping("/reEvaluation")
    @Operation(summary = "重新评估")
    public void reEvaluation(ModelAssessTaskManualPageReqVO pageReqVO) {
        //TODO 自动评估-重新评估待补充
    }

}
