package com.sonic.frog.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sonic.frog.dao.ChatModelDictDao;
import com.sonic.frog.domain.entity.ChatModelDict;
import com.sonic.frog.domain.output.ChatModelDictOutput;
import com.sonic.frog.service.ChatModelDictService;
import com.sonic.frog.utils.BeanConver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 对话模型字典服务实现类
 */
@Service
@Slf4j
public class ChatModelDictServiceImpl extends ServiceImpl<ChatModelDictDao, ChatModelDict> implements ChatModelDictService {
    @Override
    public List<ChatModelDictOutput> getChatModelDictList() {
        List<ChatModelDict> list = list(Wrappers.<ChatModelDict>lambdaQuery().eq(ChatModelDict::getIsDelete, false).orderByDesc(ChatModelDict::getSort));
        return BeanConver.copeList(list, ChatModelDictOutput.class);
    }

    @Override
    public String getModelNameByCode(String modelCode) {
        ChatModelDict chatModelDict = getOne(Wrappers.<ChatModelDict>lambdaQuery().eq(ChatModelDict::getCode, modelCode).last("limit 1"));
        return chatModelDict != null ? chatModelDict.getName() : null;
    }

    @Override
    public ChatModelDict getDefaultChatModel() {
        return getOne(Wrappers.<ChatModelDict>lambdaQuery().eq(ChatModelDict::getIsDefault, true).last("limit 1"));
    }
}