package ai.decompile.analysis.model.dto;

import ai.decompile.analysis.model.entity.StaticFunction;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

public record FunctionSummaryResponse(
    UUID id,
    UUID analysisId,
    String name,
    String resolvedName,
    String address,
    int size,
    String flags) {

  public static FunctionSummaryResponse from(StaticFunction f) {
    return from(f, null);
  }

  public static FunctionSummaryResponse from(StaticFunction f, Map<String, String> resolution) {
    var resolved = Objects.nonNull(resolution) ? resolution.get(f.getName()) : null;
    return new FunctionSummaryResponse(
        f.getId(),
        f.getAnalysis().getId(),
        f.getName(),
        resolved,
        f.getAddress(),
        f.getFunctionSize() != null ? f.getFunctionSize() : 0,
        f.getFlags());
  }
}
