/**
 * 
 */
package org.springblade.resource;

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

import org.springblade.modules.system.entity.DatasourceFunction;
import org.springblade.modules.system.service.normal.DatasourceFunctionService;
import org.springblade.system.client.DatasourceFunctionClient;
import org.springblade.system.client.model.DatasouceFunctionModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author wookvn
 *
 */
@RestController
@ApiIgnore
public class DatasourceFunctionResource implements DatasourceFunctionClient {

	@Autowired
	private DatasourceFunctionService functionService;
	
	@Override
	public List<DatasouceFunctionModel> list(Integer dsType, String tenantId) {
		List<DatasourceFunction> dataList = functionService.list(Wrappers.<DatasourceFunction>lambdaQuery().eq(DatasourceFunction::getTenantId, tenantId).eq(DatasourceFunction::getDsType, dsType));
		List<DatasouceFunctionModel> resultList = new ArrayList<>();
		if(CollectionUtil.isEmpty(dataList)) {
			return resultList;
		}
		for(DatasourceFunction dsFunc : dataList) {
			DatasouceFunctionModel functionModel = BeanUtil.copyProperties(dsFunc, DatasouceFunctionModel.class, "funcType", "funcAttr");
			functionModel.setFuncAttr(dsFunc.getFuncAttr().getValue());
			functionModel.setFuncType(dsFunc.getFuncType().getValue());
			resultList.add(functionModel);
		}
		return resultList;
	}

}
