package com.airlock.iam.plugin.config.manipulator;

import com.airlock.iam.plugin.api.config.ConfigurationContext;
import com.airlock.iam.plugin.api.config.ConfigurationEnvironment;
import com.airlock.iam.plugin.framework.misc.config.modification.ConfigModificationItem;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public record PropertyInfo(String pluginId, String property, ConfigurationEnvironment environment, ConfigurationContext context) {
   public static PropertyInfo toPropertyInfo(ConfigModificationItem configModification) {
      return builder()
         .pluginId(configModification.targetId())
         .property(configModification.targetProperty())
         .context(ConfigurationContext.configurationContext(configModification.targetContext().orElse(null)))
         .environment(ConfigurationEnvironment.configurationEnvironment(configModification.targetEnv().orElse(null)))
         .build();
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public PropertyInfo.PropertyInfoBuilder toBuilder() {
      return new PropertyInfo.PropertyInfoBuilder().pluginId(this.pluginId).property(this.property).environment(this.environment).context(this.context);
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class PropertyInfoBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String pluginId;
      @SuppressFBWarnings(justification = "generated code")
      private String property;
      @SuppressFBWarnings(justification = "generated code")
      private ConfigurationEnvironment environment;
      @SuppressFBWarnings(justification = "generated code")
      private ConfigurationContext context;

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

      @SuppressFBWarnings(justification = "generated code")
      public PropertyInfo.PropertyInfoBuilder pluginId(String pluginId) {
         this.pluginId = pluginId;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public PropertyInfo.PropertyInfoBuilder property(String property) {
         this.property = property;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public PropertyInfo.PropertyInfoBuilder environment(ConfigurationEnvironment environment) {
         this.environment = environment;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public PropertyInfo.PropertyInfoBuilder context(ConfigurationContext context) {
         this.context = context;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public PropertyInfo build() {
         return new PropertyInfo(this.pluginId, this.property, this.environment, this.context);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "PropertyInfo.PropertyInfoBuilder(pluginId="
            + this.pluginId
            + ", property="
            + this.property
            + ", environment="
            + this.environment
            + ", context="
            + this.context
            + ")";
      }
   }
}
