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

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
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.module.llm.controller.admin.modelassessstoplist.vo.*;
import cn.iocoder.yudao.module.llm.dal.dataobject.modelassessstoplist.ModelAssessStoplistDO;
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 cn.iocoder.yudao.module.llm.dal.mysql.modelassessstoplist.ModelAssessStoplistMapper;

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 ModelAssessStoplistServiceImpl implements ModelAssessStoplistService {

    @Resource
    private ModelAssessStoplistMapper modelAssessStoplistMapper;

    @Override
    public Long createModelAssessStoplist(ModelAssessStoplistSaveReqVO createReqVO) {
        // 插入
        ModelAssessStoplistDO modelAssessStoplist = BeanUtils.toBean(createReqVO, ModelAssessStoplistDO.class);
        modelAssessStoplistMapper.insert(modelAssessStoplist);
        // 返回
        return modelAssessStoplist.getId();
    }

    @Override
    public void updateModelAssessStoplist(ModelAssessStoplistSaveReqVO updateReqVO) {
        // 校验存在
        validateModelAssessStoplistExists(updateReqVO.getId());
        // 更新
        ModelAssessStoplistDO updateObj = BeanUtils.toBean(updateReqVO, ModelAssessStoplistDO.class);
        modelAssessStoplistMapper.updateById(updateObj);
    }

    @Override
    public void deleteModelAssessStoplist(Long id) {
        // 校验存在
        validateModelAssessStoplistExists(id);
        // 删除
        LambdaUpdateWrapper<ModelAssessStoplistDO> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(ModelAssessStoplistDO::getId, id)
                        .set(ModelAssessStoplistDO::getDeleted, true);
        modelAssessStoplistMapper.update(wrapper);
    }

    private void validateModelAssessStoplistExists(Long id) {
        if (modelAssessStoplistMapper.selectById(id) == null) {
            throw exception(MODEL_ASSESS_STOPLIST_NOT_EXISTS);
        }
    }

    @Override
    public ModelAssessStoplistDO getModelAssessStoplist(Long id) {
        return modelAssessStoplistMapper.selectById(id);
    }

    @Override
    public PageResult<ModelAssessStoplistDO> getModelAssessStoplistPage(ModelAssessStoplistPageReqVO pageReqVO) {
        return modelAssessStoplistMapper.selectPage(pageReqVO);
    }

    @Override
    public List<ModelAssessStoplistDO> getModelAssessStoplistAll() {
        LambdaUpdateWrapper<ModelAssessStoplistDO> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(ModelAssessStoplistDO::getDeleted, false);
        return modelAssessStoplistMapper.selectList(wrapper);
    }

}