package com.pjilisense.flxai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pjilisense.flxai.base.service.impl.CrudServiceImpl;
import com.pjilisense.flxai.dao.AppToolsSetDao;
import com.pjilisense.flxai.dto.AppToolsSetDTO;
import com.pjilisense.flxai.entity.AppToolsSetEntity;
import com.pjilisense.flxai.service.AppToolsSetService;
import cn.hutool.core.util.StrUtil;
import com.pjilisense.flxai.utils.MapUtils;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * AI应用工具集
 *
 * @author liushujing liushujing@philisense.com
 * @since 1.0.0 2024-12-12
 */
@Service
public class AppToolsSetServiceImpl extends CrudServiceImpl<AppToolsSetDao, AppToolsSetEntity, AppToolsSetDTO> implements AppToolsSetService {

    @Override
    public QueryWrapper<AppToolsSetEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<AppToolsSetEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }

    public QueryWrapper<AppToolsSetEntity> getWrapperAll(Map<String, Object> params){
        String istool = (String)params.get("istool");
        QueryWrapper<AppToolsSetEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(istool), "istool", istool);
        wrapper.orderByAsc("classification","sort");
        return wrapper;
    }
    @Override
    public Map<String, Object> getAllAiTools() {
        Map<String, Object> params =new HashMap<>();
        params.put("istool","0");
        List<AppToolsSetEntity> entityList =baseDao.selectList(getWrapperAll(params));
        params.clear();
        for(AppToolsSetEntity entity : entityList){
            String key = entity.getClassification();
            if(params.get(key)==null){
                params.put(key,new ArrayList<Map<String,Object>>());
            }
            ((ArrayList<Map<String,Object>>)params.get(key)).add(MapUtils.objectToMap(entity));
        }
        Map<String, Object> ret =new LinkedHashMap<>();
        ret.put("rmtj",params.get("rmtj"));
        ret.put("chat",params.get("chat"));
        ret.put("writing",params.get("writing"));
        ret.put("conversation",params.get("conversation"));
        ret.put("video",params.get("video"));
        ret.put("office",params.get("office"));
        ret.put("digitalPeople",params.get("digitalPeople"));
        ret.put("education",params.get("education"));
        ret.put("programming",params.get("programming"));
        ret.put("audio",params.get("audio"));
        return ret;
    }
}