package com.agent.management.rag.controller;

import com.agent.management.common.Result;
import com.agent.management.rag.bridge.RagAiBridgeClient;
import com.agent.management.rag.model.RagEvidence;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/rag")
@RequiredArgsConstructor
public class RagAnswerController {
    private final RagAiBridgeClient bridge;

    @PostMapping("/answer")
    public Result<Map<String, Object>> answer(@RequestBody AnswerRequest request) {
        return Result.success(bridge.answer(Map.of(
                "question", request.getQuestion(),
                "evidences", request.getEvidences() == null ? List.of() : request.getEvidences()
        )));
    }

    @Data
    public static class AnswerRequest {
        private String question;
        private List<RagEvidence> evidences;
    }
}
