package com.qmth.jkserver.core.cache;

import com.qmth.jkserver.service.CommonCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class JkCacheService implements IJkCacheService {

//    @Autowired
//    private RedisCacheDao redisCacheDao;

    @Autowired
    private MemoryCacheDao memoryCacheDao;

    @Resource
    CommonCacheService commonCacheService;

    @Override
    public Object getObj(String key) {
//        SysConfig jkserverSingle = commonCacheService.addSysConfigCache(SystemConstant.JKSERVER_SINGLE);
//        Optional.ofNullable(jkserverSingle).orElseThrow(() -> new JkServerException("未配置是否单例部署"));
//        boolean single = Boolean.valueOf(jkserverSingle.getConfigValue());
//        if (single) {
        return memoryCacheDao.getObj(key);
//        } else {
//            return redisCacheDao.getObj(key);
//        }
    }

    @Override
    public Object setObj(String key, Object value, int expireTime) {
//        SysConfig jkserverSingle = commonCacheService.addSysConfigCache(SystemConstant.JKSERVER_SINGLE);
//        Optional.ofNullable(jkserverSingle).orElseThrow(() -> new JkServerException("未配置是否单例部署"));
//        boolean single = Boolean.valueOf(jkserverSingle.getConfigValue());
//        if (single) {
        return memoryCacheDao.setObj(key, value, expireTime);
//        } else {
//            return redisCacheDao.setObj(key, value, expireTime);
//        }
    }

    @Override
    public boolean delObj(String key) {
//        SysConfig jkserverSingle = commonCacheService.addSysConfigCache(SystemConstant.JKSERVER_SINGLE);
//        Optional.ofNullable(jkserverSingle).orElseThrow(() -> new JkServerException("未配置是否单例部署"));
//        boolean single = Boolean.valueOf(jkserverSingle.getConfigValue());
//        if (single) {
        return memoryCacheDao.delObj(key);
//        } else {
//            return redisCacheDao.delObj(key);
//        }
    }
}
