package ai.decompile.ai.model.entity;

import ai.decompile.ai.model.jdbc.PostgreSQLVectorJdbcType;
import jakarta.persistence.*;
import java.time.Instant;
import java.util.UUID;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.annotations.JdbcTypeRegistration;
import org.hibernate.type.SqlTypes;

@Entity
@Table(name = "embedding_chunk")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JdbcTypeRegistration(PostgreSQLVectorJdbcType.class)
public class EmbeddingChunk {
  @Id
  @GeneratedValue(strategy = GenerationType.UUID)
  private UUID id;

  @Column(name = "binary_id", nullable = false)
  private UUID binaryId;

  @Column(name = "chunk_type", nullable = false, length = 30)
  private String chunkType;

  @Column(name = "source_type", length = 30)
  private String sourceType;

  @Column(name = "source_id")
  private UUID sourceId;

  @Column(nullable = false, columnDefinition = "TEXT")
  private String content;

  @JdbcTypeCode(SqlTypes.VECTOR)
  @Column(name = "embedding", columnDefinition = "vector(4096)")
  private float[] embedding;

  @JdbcTypeCode(SqlTypes.JSON)
  @Column(name = "metadata", columnDefinition = "jsonb")
  private String metadata;

  @Column(name = "token_count")
  private Integer tokenCount;

  @CreationTimestamp
  @Column(name = "created_at", nullable = false, updatable = false)
  private Instant createdAt;
}
