package ai.decompile.workspace.model.entity;

import ai.decompile.analysis.model.entity.StaticAnalysis;
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 = "binaries")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Binary {
  @Id
  @GeneratedValue(strategy = GenerationType.UUID)
  private UUID id;

  @Column(nullable = false)
  private String filename;

  @Column(name = "file_size", nullable = false)
  private long fileSize;

  @Column(length = 30)
  private String format;

  @Column(length = 30)
  private String architecture;

  @Column(length = 100)
  private String compiler;

  @Column(name = "file_path", nullable = false, length = 500)
  private String filePath;

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "project_id", nullable = false)
  private Project project;

  @Column(name = "static_analysis_done", nullable = false)
  @Builder.Default
  private boolean staticAnalysisDone = false;

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

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

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

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