package cn.iocoder.yudao.module.llm.service.modelassesstaskmanual;

import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.vo.ModelAssessDimensionPageReqVO;
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.dal.mysql.modelassesstaskmanual.ModelAssessDimensionMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;


import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.llm.enums.ErrorCodeConstants.*;

/**
 * 评估维度定义 Service 实现类
 *
 * @author 华大大模型
 */
@Service
@Validated
public class ModelAssessDimensionServiceImpl implements ModelAssessDimensionService {

    @Resource
    private ModelAssessDimensionMapper modelAssessDimensionMapper;

    @Override
    public Long createModelAssessDimension(ModelAssessDimensionSaveReqVO createReqVO) {
        // 插入
        ModelAssessDimensionDO modelAssessDimension = BeanUtils.toBean(createReqVO, ModelAssessDimensionDO.class);
        modelAssessDimensionMapper.insert(modelAssessDimension);
        // 返回
        return modelAssessDimension.getId();
    }

    @Override
    public void updateModelAssessDimension(ModelAssessDimensionSaveReqVO updateReqVO) {
        // 校验存在
        validateModelAssessDimensionExists(updateReqVO.getId());
        // 更新
        ModelAssessDimensionDO updateObj = BeanUtils.toBean(updateReqVO, ModelAssessDimensionDO.class);
        modelAssessDimensionMapper.updateById(updateObj);
    }

    @Override
    public void deleteModelAssessDimension(Long id) {
        // 校验存在
        validateModelAssessDimensionExists(id);
        // 删除
        modelAssessDimensionMapper.deleteById(id);
    }

    private void validateModelAssessDimensionExists(Long id) {
        if (modelAssessDimensionMapper.selectById(id) == null) {
            throw exception(MODEL_ASSESS_DIMENSION_NOT_EXISTS);
        }
    }

    @Override
    public ModelAssessDimensionDO getModelAssessDimension(Long id) {
        return modelAssessDimensionMapper.selectById(id);
    }

    @Override
    public PageResult<ModelAssessDimensionDO> getModelAssessDimensionPage(ModelAssessDimensionPageReqVO pageReqVO) {
        return modelAssessDimensionMapper.selectPage(pageReqVO);
    }

    @Override
    public List<ModelAssessDimensionDO> getModelAssessDimensionAll() {
        LambdaQueryWrapper<ModelAssessDimensionDO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ModelAssessDimensionDO::getDeleted,false);
        return modelAssessDimensionMapper.selectList(wrapper);
    }

}