package com.izouma.nineth.config;

import io.github.bucket4j.distributed.proxy.ProxyManager;
import org.redisson.api.RedissonClient;
import org.redisson.command.CommandSyncService;
import org.redisson.config.ConfigSupport;
import org.redisson.connection.ConnectionManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

@Configuration
public class Bucket4jConfig {

    @Bean
    ProxyManager<String> proxyManager(RedissonClient client) {
        ConnectionManager connectionManager = ConfigSupport.createConnectionManager(client.getConfig());
        CommandSyncService commandSyncService = new CommandSyncService(connectionManager, null);
        return new RedissonBasedProxyManager(commandSyncService, Duration.ofMinutes(10));
    }
}
