package com.airlock.iam.oauth2.domain.model.session;

import com.airlock.iam.base.api.domain.model.Entity;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.HashSet;
import java.util.Set;
import lombok.NonNull;

public final class OAuth2Session implements Entity<OAuth2Session> {
   private final OAuth2SessionId id;
   private final Set<OAuth2CustomSessionAttribute> customAttributes;
   private final OAuth2SessionClaims claims;

   public OAuth2Session(@NonNull OAuth2SessionId id, @NonNull OAuth2SessionClaims claims, Set<OAuth2CustomSessionAttribute> customAttributes) {
      if (id == null) {
         throw new NullPointerException("id is marked non-null but is null");
      }

      if (claims == null) {
         throw new NullPointerException("claims is marked non-null but is null");
      }

      this.id = id;
      this.claims = claims;
      this.customAttributes = customAttributes != null ? new HashSet<>(customAttributes) : new HashSet<>();
   }

   public Set<OAuth2CustomSessionAttribute> getCustomAttributes() {
      return Set.copyOf(this.customAttributes);
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public OAuth2SessionId getId() {
      return this.id;
   }

   @SuppressFBWarnings(justification = "generated code")
   public OAuth2SessionClaims getClaims() {
      return this.claims;
   }
}
