package thyyxxk.webserver.service.hutoolcache;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import thyyxxk.webserver.dao.his.ca.CaRedisDao;
import thyyxxk.webserver.entity.ca.CaSignRedis;

import java.util.List;

@Component
@RequiredArgsConstructor
public class CaCache implements HutoolCacheInterface<String> {
    private final CaRedisDao dao;

    @Override
    public void del(String key) {
        dao.deleteById(key);
    }

    @Override
    public void put(String key, String value) {
        if (value == null) {
            return;
        }
        del(key);
        dao.insert(CaSignRedis.builder()
                .id(key)
                .value(value)
                .build());
    }

    @Override
    public String get(String key) {
        CaSignRedis caSignRedis = dao.selectCreateById(key);
        if (caSignRedis == null) {
            return null;
        }
        return caSignRedis.getValue();
    }

    @Override
    public void clear() {
    }

    @Override
    public List<CacheAll> getAll() {
        return null;
    }

    @Override
    public String getLabel() {
        return "ca签名缓存";
    }
}
