package com.eactive.eai.rms.bap.manage.comm.server;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.eactive.eai.rms.bap.common.base.BapBaseService;

@Service("bapServerService")
public class BapServerService extends BapBaseService {

	@Autowired
	@Qualifier("bapServerDao")
	private BapServerDao dao;

	public HashMap<String, Object> selectList(int startNum,int endNum) throws Exception {

		HashMap<String, Object> paramMap = new HashMap<String, Object>();

		// 전체 목록수 얻기
		int totalCount = dao.selectListCount(paramMap);

		paramMap.put("startNum" , startNum);// 시작 record
		paramMap.put("endNum"   , endNum);// 끝 record


		List<Map<String, Object>> list = dao.selectList( paramMap );

		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("totalCount", totalCount);
		map.put("list", list);

		return map;
	}
	
	public HashMap<String, Object> selectDetail(String eaiSevrInstncName) throws Exception {
		HashMap<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("EAISevrInstncName", eaiSevrInstncName);
		return dao.selectDetail( paramMap );
	}
	
	public void update(HashMap<String, Object> paramMap) throws Exception {
		dao.update(paramMap);
	}	
	public void insert(HashMap<String, Object> paramMap) throws Exception {
		dao.insert(paramMap);
	}
	public void delete(HashMap<String, Object> paramMap) throws Exception {
		dao.delete(paramMap);
	}	

	public List<Map<String, Object>> getEaiServerIpPort() throws Exception {

		HashMap<String, String> paramMap = new HashMap<String, String>();
		return dao.getEaiServerIpPort( paramMap );
	}
	public HashMap<String, Object> getEaiServerIpPortForActiveStandby() throws Exception {
		
		HashMap<String, String> paramMap = new HashMap<String, String>();
		return dao.getEaiServerIpPortForActiveStandby( paramMap );
	}

   public void transactionMergeBapServerList(List<Map<String, String>> serverList) {

      Map<String, Object> paramMap = new HashMap<>();
      paramMap.put("serverList", serverList);

      dao.deleteNotMatchedBP03(paramMap);
      dao.upsertServerListBP03(paramMap);
   }
}