package com.airlock.iam.common.application.configuration.restclient;

import com.airlock.iam.common.infrastructure.restclient.RestClientRetryPolicy;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.core.Response;

@Plugin(description = "Retry if the REST server is not reachable.")
public class RetryIfServerNotReachablePolicyConfig implements RestClientRetryPolicy {
   @Override
   public boolean retryRequestWithResponse(Response response) {
      return false;
   }

   @Override
   public boolean retryRequestWithProcessingException(ProcessingException exception) {
      return true;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static RetryIfServerNotReachablePolicyConfig.RetryIfServerNotReachablePolicyConfigBuilder builder() {
      return new RetryIfServerNotReachablePolicyConfig.RetryIfServerNotReachablePolicyConfigBuilder();
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class RetryIfServerNotReachablePolicyConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      RetryIfServerNotReachablePolicyConfigBuilder() {
      }

      @SuppressFBWarnings(justification = "generated code")
      public RetryIfServerNotReachablePolicyConfig build() {
         return new RetryIfServerNotReachablePolicyConfig();
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "RetryIfServerNotReachablePolicyConfig.RetryIfServerNotReachablePolicyConfigBuilder()";
      }
   }
}
