package ai.decompile.analysis.model.entity;

import ai.decompile.workspace.model.entity.Binary;
import jakarta.persistence.*;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

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

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "binary_id", nullable = false)
  private Binary binary;

  @Column(name = "job_id")
  private UUID jobId;

  @Column(nullable = false, length = 20)
  private String engine;

  @Column(nullable = false, length = 50)
  private String status;

  @Column(name = "function_count", nullable = false)
  @Builder.Default
  private int functionCount = 0;

  @Column(name = "entry_point", length = 100)
  private String entryPoint;

  @OneToMany(
      mappedBy = "analysis",
      cascade = CascadeType.ALL,
      orphanRemoval = true,
      fetch = FetchType.LAZY)
  @Builder.Default
  private List<StaticFunction> functions = new ArrayList<>();

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

  @UpdateTimestamp
  @Column(name = "updated_at", nullable = false)
  private Instant updatedAt;
}
