package com.eactive.eai.rms.common.combo.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.eactive.eai.rms.common.combo.IbatisComboService;
import com.eactive.eai.rms.common.datasource.DataSourceContextHolder;
import com.eactive.eai.rms.common.datasource.DataSourceType;
import com.eactive.eai.rms.common.datasource.DataSourceTypeManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@Deprecated
public class IbatisComboServiceImpl implements IbatisComboService {

	private ComboDao ibatisComboDao;

	@Autowired
	protected IbatisComboServiceImpl(ComboDao ibatisComboDao) {
		this.ibatisComboDao = ibatisComboDao;
	}

	@Override
	public List<Map<String, Object>> selectListComboForTable(String tableName, String codeColumn, String nameColumn) {
		HashMap<String, Object> paramMap = new HashMap<>();
		paramMap.put("tableName", tableName);
		paramMap.put("codeColumn", codeColumn);
		paramMap.put("nameColumn", nameColumn);
		return ibatisComboDao.selectListComboForTable(paramMap);
	}

	@Override
	public List<Map<String, Object>> selectListComboForTable(String tableName, String codeColumn, String nameColumn,
			String where) {
		HashMap<String, Object> paramMap = new HashMap<>();
		paramMap.put("tableName", tableName);
		paramMap.put("codeColumn", codeColumn);
		paramMap.put("nameColumn", nameColumn);
		paramMap.put("where", where);
		return ibatisComboDao.selectListComboForTable(paramMap);
	}

	@Deprecated
	public List<Map<String, Object>> selectListComboForTable(String tableName, String codeColumn, String nameColumn,
			String where, String sortColumn) {
		HashMap<String, Object> paramMap = new HashMap<>();
		paramMap.put("tableName", tableName);
		paramMap.put("codeColumn", codeColumn);
		paramMap.put("nameColumn", nameColumn);
		paramMap.put("where", where);
		paramMap.put("sortColumn", sortColumn);
		return ibatisComboDao.selectListComboForTable(paramMap);
	}

	@Override
	@Deprecated
	public List<Map<String, Object>> selectListComboForTableWithCode(String tableName, String codeColumn,
			String nameColumn) {
		HashMap<String, Object> paramMap = new HashMap<>();
		paramMap.put("tableName", tableName);
		paramMap.put("codeColumn", codeColumn);
		paramMap.put("nameColumn", nameColumn);
		return ibatisComboDao.selectListComboForTableWithCode(paramMap);
	}
	
	@Override
	@Deprecated
	public List<Map<String, Object>> selectCM01ComboList(String codeColumn, String nameColumn) {
		HashMap<String, Object> paramMap = new HashMap<>();
		DataSourceType dataSourceType = DataSourceTypeManager.getDataSourceType(DataSourceTypeManager.APIGW);
		DataSourceContextHolder.setDataSourceType(dataSourceType);
		
		paramMap.put("schemaId", dataSourceType.getSchema());
		paramMap.put("codeColumn", codeColumn);
		paramMap.put("nameColumn", nameColumn);
		return ibatisComboDao.selectCM01ComboList(paramMap);
	}

}
