package com.sonic.common.ratelimit.impl;

import java.util.Optional;

import com.sonic.common.ratelimit.RateLimiter;
import com.sonic.common.ratelimit.RateLimiterClient;
import com.google.common.collect.ImmutableList;

import lombok.Setter;

public class DummyRateLimiter implements RateLimiter {

    private RateLimiterClient.RateLimiterReq rateLimiterReq;
    @Setter
    private boolean result = true;

    public DummyRateLimiter(RateLimiterClient.RateLimiterReq rateLimiterReq) {
        this.rateLimiterReq = rateLimiterReq;
    }

    @Override
    public Optional<Permit> tryAcquire(Object value) {
        return result ? Optional.of(Permit.builder().cancelRunners(ImmutableList.of()).build()) : Optional.empty();
    }

    @Override
    public WindowType getWindowType() {
        return rateLimiterReq.getWindowType();
    }
}
