package com.eactive.eai.transformer;

import static org.mockito.BDDMockito.given;

import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;

import com.eactive.eai.common.lifecycle.LifecycleException;
import com.eactive.eai.common.util.ApplicationContextProvider;
import com.eactive.eai.transformer.dao.excel.FunctionExcelDao;
import com.eactive.eai.transformer.dao.excel.LayoutExcelDao;
import com.eactive.eai.transformer.dao.excel.LayoutTypeExcelDao;
import com.eactive.eai.transformer.dao.excel.TransformExcelDao;
import com.eactive.eai.transformer.dao.jdbc.FunctionJdbcDao;
import com.eactive.eai.transformer.dao.jdbc.LayoutJdbcDao;
import com.eactive.eai.transformer.dao.jdbc.LayoutTypeJdbcDao;
import com.eactive.eai.transformer.dao.jdbc.TransformJdbcDao;
import com.eactive.eai.transformer.engine.TransformEngine;
import com.eactive.eai.transformer.function.FunctionManager;
import com.eactive.eai.transformer.function.loader.FunctionLoader;
import com.eactive.eai.transformer.function.mapper.FunctionMapper;
import com.eactive.eai.transformer.layout.LayoutManager;
import com.eactive.eai.transformer.layout.LayoutTypeManager;
import com.eactive.eai.transformer.layout.loader.LayoutLoaderImpl;
import com.eactive.eai.transformer.layout.loader.LayoutTypeLoaderImpl;
import com.eactive.eai.transformer.layout.mapper.LayoutItemMapper;
import com.eactive.eai.transformer.layout.mapper.LayoutMapper;
import com.eactive.eai.transformer.layout.mapper.LayoutTypeMapper;
import com.eactive.eai.transformer.transform.TransformManager;
import com.eactive.eai.transformer.transform.loader.TransformLoader;
import com.eactive.eai.transformer.transform.mapper.TransformEntityMapper;

@SpringBootTest(classes = { ApplicationContextProvider.class, LayoutTypeManager.class, LayoutManager.class,
		FunctionManager.class, TransformManager.class, LayoutTypeExcelDao.class, LayoutExcelDao.class,
		FunctionExcelDao.class, TransformExcelDao.class, TransformEngine.class })
@MockBean(classes = { LayoutMapper.class, LayoutItemMapper.class, LayoutTypeMapper.class, FunctionMapper.class,
		TransformEntityMapper.class, LayoutLoaderImpl.class, LayoutTypeLoaderImpl.class, FunctionLoader.class,
		TransformLoader.class, LayoutTypeJdbcDao.class, LayoutJdbcDao.class })
public class TransformExcelLoadConfiguration {

	@Autowired
	LayoutTypeExcelDao layoutTypeExcelDao;

	@MockBean
	LayoutTypeJdbcDao layoutTypeJdbcDao;

	@Autowired
	LayoutExcelDao layoutExcelDao;

	@MockBean
	LayoutJdbcDao layoutJdbcDao;

	@Autowired
	FunctionExcelDao functionExcelDao;

	@MockBean
	FunctionJdbcDao functionJdbcDao;

	@Autowired
	TransformExcelDao transformExcelDao;

	@MockBean
	TransformJdbcDao transformJdbcDao;

	@Autowired
	TransformEngine engine;

	@BeforeEach
	public void before() throws LifecycleException {

		// given layout type
		given(layoutTypeJdbcDao.load()).will(d -> layoutTypeExcelDao.load());

		// given layout
		given(layoutJdbcDao.load()).will(d -> layoutExcelDao.load());

		// given function
		given(functionJdbcDao.load()).will(d -> functionExcelDao.load());

		// given transform
		given(transformJdbcDao.load()).will(d -> transformExcelDao.load());

		// given engine start
		engine.start();
	}

}
