package com.eactive.eai.rms.bap.loader.intf;

import com.eactive.eai.rms.bap.loader.dao.InterfaceDeployDao;
import com.eactive.eai.rms.bap.loader.dao.LoaderBAPDao;
import com.eactive.eai.rms.bap.loader.dao.SearchBAPDao;
import com.eactive.eai.rms.bap.loader.intf.deploy.InterfaceDeploy;
import com.eactive.eai.rms.common.datasource.DataSourceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

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

@Service("BapInterfaceDeployService")
public class InterfaceDeployService {

   @Autowired
   @Qualifier("searchBAPDao")
   SearchBAPDao searchBAPDao;

   @Autowired
   LoaderBAPDao loaderBAPDao;

   @Autowired
   @Qualifier("BapInterfaceDeployDao")
   InterfaceDeployDao interfaceDeployDao;


   public InterfaceDeploy selectDeploy(String intfid){

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

      InterfaceDeploy interfaceDeploy = interfaceDeployDao.selectDeploy(paramMap, InterfaceDeploy.class);


      return interfaceDeploy;
   }

   public void saveDeploy(InterfaceDeploy interfaceDeploy) {

      final Map<String, Object> paramMap = new HashMap<>();
      paramMap.put("intfid", interfaceDeploy.getBjobmsgdstcd());

      /** DELETE **/
      interfaceDeployDao.deleteAllDeploy(paramMap, InterfaceDeploy.class);

      /** INSERT **/
      interfaceDeployDao.insertDeploy(interfaceDeploy);
   }
}
