package cn.iocoder.yudao.module.system.api.dicttenant;

import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.api.dicttenant.dto.DictDataTenantRespDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.dictTenant.DictDataTenantDO;
import cn.iocoder.yudao.module.system.service.dictTenant.DictDataTenantService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

@Service
public class DictDataTenantApiImpl implements DictDataTenantApi {

    @Resource
    private DictDataTenantService dictDataTenantService;

    @Override
    public DictDataTenantRespDTO getDictData(String dictType, String value) {
        if (StrUtil.isBlank(dictType) || StrUtil.isBlank(value)) {
            return null;
        }
        DictDataTenantDO dictDataTenantDO = dictDataTenantService.getDictData(dictType, value);
        return BeanUtils.toBean(dictDataTenantDO, DictDataTenantRespDTO.class);
    }

    @Override
    public List<DictDataTenantRespDTO> getDictDataList(String dictType) {
        if (StrUtil.isBlank(dictType)) {
            return Collections.emptyList();
        }
        List<DictDataTenantDO> dictDataTenantDOList = dictDataTenantService.getDictDataListByDictType(dictType);
        return BeanUtils.toBean(dictDataTenantDOList, DictDataTenantRespDTO.class);
    }
}
