package com.banesco.infrastructure.redis;

import com.banesco.domain.ports.outbound.RedisPort;
import io.quarkus.redis.datasource.RedisDataSource;
import io.quarkus.redis.datasource.value.SetArgs;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j;

@ApplicationScoped
@Slf4j
public class RedisAdapter implements RedisPort {


    private final RedisDataSource redisDataSource;

    public RedisAdapter(RedisDataSource redisDataSource) {
        this.redisDataSource = redisDataSource;
    }

    @Override
    public String findValue(String key) {
        String result = redisDataSource.value(String.class).get(key);
        log.info("REDIS FIND key: [{}] value: [{}]", key, result);
        return result;
    }

    @Override
    public void setValue(String key, String objectStr, long expiration) {
        SetArgs setArgs = new SetArgs();
        setArgs.ex(expiration);
        log.info("REDIS SAVE key: [{}] value: [{}]", key, objectStr);
        redisDataSource.value(String.class).set(key, objectStr, setArgs);
    }
}
