package com.airlock.iam.application.parameters.domain.model;

import com.google.common.base.Preconditions;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.nio.file.Path;
import java.util.Objects;
import java.util.regex.Pattern;

public final class IamProfile {
   public static final Pattern PROFILE_NAME_PATTERN = Pattern.compile("^[a-zA-Z0-9]+[\\w-.]*$");
   private final IamInstance iamInstance;
   private final String name;

   public IamProfile(IamInstance iamInstance, String name) {
      Objects.requireNonNull(iamInstance);
      Preconditions.checkArgument(PROFILE_NAME_PATTERN.matcher(name).matches());
      this.iamInstance = iamInstance;
      this.name = name;
   }

   public Path parametersFile() {
      return this.iamInstance.profilesDirectory().resolve(this.name + ".properties");
   }

   @SuppressFBWarnings(justification = "generated code")
   public IamInstance iamInstance() {
      return this.iamInstance;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      } else if (!(o instanceof IamProfile other)) {
         return false;
      } else {
         Object this$iamInstance = this.iamInstance;
         Object other$iamInstance = other.iamInstance;
         if (this$iamInstance == null ? other$iamInstance == null : this$iamInstance.equals(other$iamInstance)) {
            Object this$name = this.name;
            Object other$name = other.name;
            return this$name == null ? other$name == null : this$name.equals(other$name);
         } else {
            return false;
         }
      }
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public int hashCode() {
      int PRIME = 59;
      int result = 1;
      Object $iamInstance = this.iamInstance;
      result = result * 59 + ($iamInstance == null ? 43 : $iamInstance.hashCode());
      Object $name = this.name;
      return result * 59 + ($name == null ? 43 : $name.hashCode());
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "IamProfile(iamInstance=" + this.iamInstance() + ", name=" + this.name() + ")";
   }
}
