package ai.decompile.analysis.controller;

import ai.decompile.analysis.model.dto.FunctionDetailResponse;
import ai.decompile.analysis.model.dto.XrefResponse;
import ai.decompile.analysis.service.AnalysisService;
import io.swagger.v3.oas.annotations.Operation;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class FunctionController {
  private final AnalysisService analysisService;

  @Operation(
      summary = "Get function details",
      description =
          "Retrieve full details of a function including assembly, decompiled code, and xref counts.",
      tags = {"Function"},
      operationId = "getFunction")
  @GetMapping("/functions/{functionId}")
  public FunctionDetailResponse getFunction(@PathVariable UUID functionId) {
    return analysisService.getFunction(functionId);
  }

  @Operation(
      summary = "List callers of a function",
      description = "Retrieve functions that call this function (incoming references).",
      tags = {"Function"},
      operationId = "getCallers")
  @GetMapping("/functions/{functionId}/callers")
  public List<XrefResponse> getCallers(@PathVariable UUID functionId) {
    return analysisService.getCallers(functionId);
  }

  @Operation(
      summary = "List callees of a function",
      description = "Retrieve functions that this function calls (outgoing references).",
      tags = {"Function"},
      operationId = "getCallees")
  @GetMapping("/functions/{functionId}/callees")
  public List<XrefResponse> getCallees(@PathVariable UUID functionId) {
    return analysisService.getCallees(functionId);
  }
}
