package com.seer.teach.teacher.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seer.teach.common.constants.CommonConstant;
import com.seer.teach.common.enums.ResultCodeEnum;
import com.seer.teach.common.utils.AssertUtils;
import com.seer.teach.teacher.module.entity.AiScenarioConfigEntity;
import com.seer.teach.teacher.module.entity.AiScenarioEntity;
import com.seer.teach.teacher.module.mapper.AiScenarioConfigMapper;
import com.seer.teach.teacher.service.IAiScenarioConfigService;
import com.seer.teach.teacher.service.IAiScenarioService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 * AI场景配置表 服务实现类
 * </p>
 *
 * @author System
 * @since 2025-10-27
 */
@RequiredArgsConstructor
@Service
public class AiScenarioConfigServiceImpl extends ServiceImpl<AiScenarioConfigMapper, AiScenarioConfigEntity> implements IAiScenarioConfigService {

    private final IAiScenarioService aiScenarioService;


    @Override
    public AiScenarioConfigEntity getOneByScenarioCode(String scenarioCode) {
        LambdaQueryWrapper<AiScenarioEntity> scenarioWrapper = new LambdaQueryWrapper<>();
        scenarioWrapper.eq(AiScenarioEntity::getScenarioCode, scenarioCode);
        AiScenarioEntity aiScenario = aiScenarioService.getOne(scenarioWrapper);
        AssertUtils.notNull(aiScenario, ResultCodeEnum.SCENARIO_NOT_FOUND);
        LambdaQueryWrapper<AiScenarioConfigEntity> configWrapper = new LambdaQueryWrapper<>();
        configWrapper.eq(AiScenarioConfigEntity::getScenarioId, aiScenario.getId());
        configWrapper.eq(AiScenarioConfigEntity::getEnabled, CommonConstant.ENABLE);
        configWrapper.orderByAsc(AiScenarioConfigEntity::getPriority);
        return super.getOne(configWrapper);
    }
}