package com.airlock.iam.common.application.query.restriction;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class RestrictionProviders {
   private List<QueryFilterRestrictionProvider> providers;

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

   @SuppressFBWarnings(justification = "generated code")
   public List<QueryFilterRestrictionProvider> getProviders() {
      return this.providers;
   }

   @SuppressFBWarnings(justification = "generated code")
   public RestrictionProviders(List<QueryFilterRestrictionProvider> providers) {
      this.providers = providers;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class RestrictionProvidersBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private ArrayList<QueryFilterRestrictionProvider> providers;

      @SuppressFBWarnings(justification = "generated code")
      RestrictionProvidersBuilder() {
      }

      @SuppressFBWarnings(justification = "generated code")
      public RestrictionProviders.RestrictionProvidersBuilder provider(QueryFilterRestrictionProvider provider) {
         if (this.providers == null) {
            this.providers = new ArrayList<>();
         }

         this.providers.add(provider);
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RestrictionProviders.RestrictionProvidersBuilder providers(Collection<? extends QueryFilterRestrictionProvider> providers) {
         if (providers == null) {
            throw new NullPointerException("providers cannot be null");
         }

         if (this.providers == null) {
            this.providers = new ArrayList<>();
         }

         this.providers.addAll(providers);
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RestrictionProviders.RestrictionProvidersBuilder clearProviders() {
         if (this.providers != null) {
            this.providers.clear();
         }

         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RestrictionProviders build() {
         return new RestrictionProviders(switch (this.providers == null ? 0 : this.providers.size()) {
            case 0 -> Collections.emptyList();
            case 1 -> Collections.singletonList(this.providers.get(0));
            default -> Collections.unmodifiableList(new ArrayList<>(this.providers));
         });
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "RestrictionProviders.RestrictionProvidersBuilder(providers=" + this.providers + ")";
      }
   }
}
