package com.l7tech.server.secureconversation;

import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.imp.PersistentEntityImp;
import com.l7tech.util.Charsets;
import com.l7tech.util.HexUtils;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;

@Entity
@Proxy(lazy = false)
@Table(name = "wssc_session")
public class StoredSecureConversationSession extends PersistentEntityImp {
   private String sessionKey;
   private boolean inbound;
   private String identifier;
   private long created;
   private long expires;
   private String namespace;
   private String token;
   private String serviceUrl;
   private String encryptedKey;
   private Goid providerId;
   private String userId;
   private String userLogin;
   static final long serialVersionUID = 3826066075200087098L;

   public StoredSecureConversationSession(String var1, long var2, long var4, String var6, String var7, Goid var8, String var9, String var10) {
      this.sessionKey = generateSessionKey(var1);
      this.inbound = true;
      this.identifier = var1;
      this.created = var2;
      this.expires = var4;
      this.namespace = var6;
      this.encryptedKey = var7;
      this.providerId = var8;
      this.userId = var9;
      this.userLogin = var10;
   }

   public StoredSecureConversationSession(
      String var1, Goid var2, String var3, String var4, String var5, long var6, long var8, String var10, String var11, String var12
   ) {
      this.sessionKey = generateSessionKey(var2, var3, var1);
      this.inbound = false;
      this.identifier = var5;
      this.serviceUrl = var1;
      this.created = var6;
      this.expires = var8;
      this.namespace = var10;
      this.token = var11;
      this.encryptedKey = var12;
      this.providerId = var2;
      this.userId = var3;
      this.userLogin = var4;
   }

   @Column(name = "session_key_hash", nullable = false, unique = true, updatable = false, length = 128)
   public String getSessionKey() {
      return this.sessionKey;
   }

   public void setSessionKey(String var1) {
      this.sessionKey = var1;
   }

   @Column(name = "inbound", updatable = false)
   public boolean isInbound() {
      return this.inbound;
   }

   public void setInbound(boolean var1) {
      this.inbound = var1;
   }

   @Column(name = "identifier", nullable = false, updatable = false, length = 4096)
   public String getIdentifier() {
      return this.identifier;
   }

   public void setIdentifier(String var1) {
      this.identifier = var1;
   }

   @Column(name = "created", updatable = false)
   public long getCreated() {
      return this.created;
   }

   public void setCreated(long var1) {
      this.created = var1;
   }

   @Column(name = "expires", updatable = false)
   public long getExpires() {
      return this.expires;
   }

   public void setExpires(long var1) {
      this.expires = var1;
   }

   @Column(name = "namespace", updatable = false, length = 4096)
   public String getNamespace() {
      return this.namespace;
   }

   public void setNamespace(String var1) {
      this.namespace = var1;
   }

   @Column(name = "token", updatable = false, length = 131072)
   public String getToken() {
      return this.token;
   }

   public void setToken(String var1) {
      this.token = var1;
   }

   @Column(name = "service_url", updatable = false, length = 4096)
   public String getServiceUrl() {
      return this.serviceUrl;
   }

   public void setServiceUrl(String var1) {
      this.serviceUrl = var1;
   }

   @Column(name = "encrypted_key", updatable = false)
   public String getEncryptedKey() {
      return this.encryptedKey;
   }

   public void setEncryptedKey(String var1) {
      this.encryptedKey = var1;
   }

   @Column(name = "provider_goid", updatable = false)
   @Type(type = "com.l7tech.server.util.GoidType")
   public Goid getProviderId() {
      return this.providerId;
   }

   public void setProviderId(Goid var1) {
      this.providerId = var1;
   }

   @Column(name = "user_id", updatable = false, length = 255)
   public String getUserId() {
      return this.userId;
   }

   public void setUserId(String var1) {
      this.userId = var1;
   }

   @Column(name = "user_login", updatable = false, length = 255)
   public String getUserLogin() {
      return this.userLogin;
   }

   public void setUserLogin(String var1) {
      this.userLogin = var1;
   }

   protected StoredSecureConversationSession() {
   }

   static String generateSessionKey(String var0) {
      return HexUtils.encodeBase64(HexUtils.getSha512Digest(var0.getBytes(Charsets.UTF8)), true);
   }

   static String generateSessionKey(Goid var0, String var1, String var2) {
      return HexUtils.encodeBase64(
         HexUtils.getSha512Digest(new byte[][]{Goid.toString(var0).getBytes(Charsets.UTF8), var1.getBytes(Charsets.UTF8), var2.getBytes(Charsets.UTF8)}), true
      );
   }
}
