package com.eactive.eai.rms.onl.transaction.apim;

import java.util.Optional;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.eactive.eai.data.entity.onl.stdmessage.StandardMessageInfo;
import com.eactive.eai.data.jpa.AbstractDataService;
import com.eactive.eai.rms.onl.transaction.apim.repository.StandardMessageInfoRepositoryForApi;

//현재 ems에 내부표준메시지가 작성되지 않아 임시로 사용
@Repository
@Transactional
public class StandardMessageInfoQueryServiceForApi extends AbstractDataService<StandardMessageInfo, String, StandardMessageInfoRepositoryForApi> {

    public Optional<StandardMessageInfo> findByEaiSvcName(String eaiSvcName){
        return repository.findByEaisvcname(eaiSvcName);
    }

    public void deleteByEaiSvcName(String eaiSvcName){
        repository.findByEaisvcname(eaiSvcName).ifPresent(repository::delete);
    }
    
    public void existsByApiFullPathAndEaiSvcNameNot(String apiFullPath, String eaiServiceName) {
    	
    	boolean isExist = repository.existsByApifullpathAndEaisvcnameNot(apiFullPath, eaiServiceName);
    	
    	if(isExist) {
    		throw new RuntimeException("API FUll PATH 가 중복되었습니다 : " + apiFullPath);
    	}
    }
}


