package com.eactive.eai.manage.session;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.eactive.eai.common.session.CacheInfoVO;
import com.eactive.eai.common.session.SessionManager;

/**
 * SessionManager(SessionManagerForIgnite/SessionManagerForEhcache) 캐시 조회를 위임하는 서비스.
 *
 * SessionManager.getInstance() 는 설정(session_manager.cacheType)에 따라 Ignite/Ehcache
 * 구현체 중 하나의 싱글턴을 반환하며, 두 구현체 모두 아래 조회 메서드를 지원한다.
 */
@Service
public class SessionCacheManageService {

    public String getCacheStatus() {
        return SessionManager.getInstance().getCacheStatus();
    }

    public String getMasterInstId() {
        return SessionManager.getInstance().getMasterInstId();
    }

    public CacheInfoVO getLoginCache() {
        return SessionManager.getInstance().getLoginCache();
    }

    public CacheInfoVO getHttpLoginCache() {
        return SessionManager.getInstance().getHttpLoginCache();
    }

    public CacheInfoVO getEvictMasterCache() {
        return SessionManager.getInstance().getEvictMasterCache();
    }

    public CacheInfoVO getTerminalCache() {
        return SessionManager.getInstance().getTerminalCache();
    }

    public CacheInfoVO getConvertUserIdCache() {
        return SessionManager.getInstance().getConvertUserIdCache();
    }

    public CacheInfoVO getSocketCache() {
        return SessionManager.getInstance().getSocketCache();
    }

    public CacheInfoVO getOutboundAccessTokenCache() {
        return SessionManager.getInstance().getOutboundAccessTokenCache();
    }

    public List<CacheInfoVO> getAllCaches() {
        List<CacheInfoVO> result = new ArrayList<>();
        result.add(getLoginCache());
        result.add(getHttpLoginCache());
        result.add(getEvictMasterCache());
        result.add(getTerminalCache());
        result.add(getConvertUserIdCache());
        result.add(getSocketCache());
        try {
            result.add(getOutboundAccessTokenCache());
        } catch (UnsupportedOperationException e) {
            // Ehcache 백엔드는 OutboundAccessToken 캐시를 지원하지 않는다.
        }
        return result;
    }
}
