package com.airlock.iam.factor.domain.model.fido;

import com.google.common.net.InternetDomainName;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public final class FidoUrlOrigin implements FidoOrigin {
   private final String origin;

   public FidoUrlOrigin(String domainName) {
      if (!isValid(domainName)) {
         throw new IllegalArgumentException(String.format("The string '%s' is not a valid internet domain name", domainName));
      }

      this.origin = "https://" + domainName;
   }

   private static boolean isValid(String domainName) {
      return InternetDomainName.isValid(domainName);
   }

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

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

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

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "FidoUrlOrigin(origin=" + this.getOrigin() + ")";
   }
}
