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

import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.vo.ModelAssessDimensionPageReqVO;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.vo.ModelAssessDimensionRespVO;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.vo.ModelAssessDimensionSaveReqVO;
import cn.iocoder.yudao.module.llm.dal.dataobject.modelassesstaskmanual.ModelAssessDimensionDO;
import cn.iocoder.yudao.module.llm.service.modelassesstaskmanual.ModelAssessDimensionService;
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/model-assess-dimension")
@Validated
public class ModelAssessDimensionController {

    @Resource
    private ModelAssessDimensionService modelAssessDimensionService;

    @PostMapping("/create")
    @Operation(summary = "创建评估维度定义")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-dimension:create')")
    public CommonResult<Long> createModelAssessDimension(@Valid @RequestBody ModelAssessDimensionSaveReqVO createReqVO) {
        return success(modelAssessDimensionService.createModelAssessDimension(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新评估维度定义")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-dimension:update')")
    public CommonResult<Boolean> updateModelAssessDimension(@Valid @RequestBody ModelAssessDimensionSaveReqVO updateReqVO) {
        modelAssessDimensionService.updateModelAssessDimension(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除评估维度定义")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('llm:model-assess-dimension:delete')")
    public CommonResult<Boolean> deleteModelAssessDimension(@RequestParam("id") Long id) {
        modelAssessDimensionService.deleteModelAssessDimension(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得评估维度定义")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-dimension:query')")
    public CommonResult<ModelAssessDimensionRespVO> getModelAssessDimension(@RequestParam("id") Long id) {
        ModelAssessDimensionDO modelAssessDimension = modelAssessDimensionService.getModelAssessDimension(id);
        return success(BeanUtils.toBean(modelAssessDimension, ModelAssessDimensionRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得评估维度定义分页")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-dimension:query')")
    public CommonResult<PageResult<ModelAssessDimensionRespVO>> getModelAssessDimensionPage(@Valid ModelAssessDimensionPageReqVO pageReqVO) {
        PageResult<ModelAssessDimensionDO> pageResult = modelAssessDimensionService.getModelAssessDimensionPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ModelAssessDimensionRespVO.class));
    }
    @GetMapping("/all")
    @Operation(summary = "获得所有评估维度定义")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-dimension:all')")
    public CommonResult<List<ModelAssessDimensionRespVO>> getModelAssessDimensionAll() {
        List<ModelAssessDimensionDO> list = modelAssessDimensionService.getModelAssessDimensionAll();
        return success(BeanUtils.toBean(list, ModelAssessDimensionRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出评估维度定义 Excel")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-dimension:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportModelAssessDimensionExcel(@Valid ModelAssessDimensionPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ModelAssessDimensionDO> list = modelAssessDimensionService.getModelAssessDimensionPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "评估维度定义.xls", "数据", ModelAssessDimensionRespVO.class,
                        BeanUtils.toBean(list, ModelAssessDimensionRespVO.class));
    }

}