package com.l7tech.gateway.common.resources;

import com.l7tech.objectmodel.imp.ZoneableEntityImp;
import com.l7tech.security.rbac.RbacAttribute;
import com.l7tech.util.Charsets;
import com.l7tech.util.DeserializeSafe;
import com.l7tech.util.HexUtils;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.annotations.Proxy;

@Entity
@Proxy(lazy = false)
@Table(name = "resource_entry")
@DeserializeSafe
public class ResourceEntry extends ZoneableEntityImp {
   private String description;
   private String uri;
   private String uriHash;
   private ResourceType type;
   private String contentType;
   private String content;
   private String resourceKey1;
   private String resourceKey2;
   private String resourceKey3;
   static final long serialVersionUID = 3299716749653085348L;

   @NotNull
   @Size(min = 0, max = 104857600)
   @Column(name = "content", length = Integer.MAX_VALUE)
   @Lob
   public String getContent() {
      return this.content;
   }

   public void setContent(String var1) {
      this.content = var1;
   }

   @NotNull
   @Size(min = 3, max = 255)
   @Column(name = "content_type", length = 255)
   public String getContentType() {
      return this.contentType;
   }

   public void setContentType(String var1) {
      this.contentType = var1;
   }

   @RbacAttribute
   @Size(min = 0, max = 255)
   @Column(name = "description", length = 255)
   public String getDescription() {
      return this.description;
   }

   public void setDescription(String var1) {
      this.description = var1;
   }

   @Size(min = 0, max = 4096)
   @Column(name = "resource_key1", length = 4096)
   public String getResourceKey1() {
      return this.resourceKey1;
   }

   public void setResourceKey1(String var1) {
      this.resourceKey1 = var1;
   }

   @Size(min = 0, max = 4096)
   @Column(name = "resource_key2", length = 4096)
   public String getResourceKey2() {
      return this.resourceKey2;
   }

   public void setResourceKey2(String var1) {
      this.resourceKey2 = var1;
   }

   @Size(min = 0, max = 4096)
   @Column(name = "resource_key3", length = 4096)
   public String getResourceKey3() {
      return this.resourceKey3;
   }

   public void setResourceKey3(String var1) {
      this.resourceKey3 = var1;
   }

   @RbacAttribute
   @NotNull
   @Column(name = "type", length = 32)
   @Enumerated(EnumType.STRING)
   public ResourceType getType() {
      return this.type;
   }

   public void setType(ResourceType var1) {
      this.type = var1;
   }

   @RbacAttribute
   @NotNull
   @Size(min = 1, max = 4096)
   @Column(name = "uri", length = 4096)
   public String getUri() {
      return this.uri;
   }

   public void setUri(String var1) {
      this.uri = var1;
      this.uriHash = null;
   }

   @NotNull
   @Size(min = 0, max = 128)
   @Column(name = "uri_hash", length = 128)
   public String getUriHash() {
      if (this.uriHash == null) {
         this.updateUriHash();
      }

      return this.uriHash;
   }

   public void setUriHash(String var1) {
      this.uriHash = var1;
   }

   @Version
   @Column(name = "version")
   public int getVersion() {
      return super.getVersion();
   }

   private void updateUriHash() {
      if (this.uri != null) {
         this.uriHash = HexUtils.encodeBase64(HexUtils.getSha512Digest(this.uri.getBytes(Charsets.UTF8)), true);
      }
   }
}
