package cn.stylefeng.team.meta.modular.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDictType;
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictRequest;
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictTypeRequest;
import cn.stylefeng.roses.kernel.dict.modular.service.DictService;
import cn.stylefeng.roses.kernel.dict.modular.service.DictTypeService;
import cn.stylefeng.team.meta.modular.pojo.dictrouting.RoutingDict;
import cn.stylefeng.team.meta.modular.pojo.dictrouting.RoutingDictType;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DictRoutingService {

    @Resource
    private DictTypeService dictTypeService;

    @Resource
    private DictService dictService;

    public List<RoutingDictType> getDictTypeList() {
        List<SysDictType> list = dictTypeService.findList(new DictTypeRequest());
        return BeanUtil.copyToList(list, RoutingDictType.class);
    }

    public List<RoutingDict> getDictItemList(Long dictTypeId) {

        DictRequest dictRequest = new DictRequest();
        dictRequest.setDictTypeId(dictTypeId);
        List<SysDict> dictList = dictService.findList(dictRequest);
        if (ObjectUtil.isEmpty(dictList)) {
            return new ArrayList<>();
        } else {
            return BeanUtil.copyToList(dictList, RoutingDict.class);
        }
    }
}
