package top.tqx.demo_1.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.tqx.demo_1.dto.KBRouteRequest;
import top.tqx.demo_1.dto.KBRouteResponse;
import top.tqx.demo_1.service.KBRouteService;

import java.util.HashMap;
import java.util.Map;

@Tag(name = "知识库路由", description = "知识库路由调试接口")
@RestController
@RequestMapping("/kb-route")
@Slf4j
public class KBRouteController {

    @Autowired
    private KBRouteService kbRouteService;

    @Operation(summary = "测试知识库路由", description = "测试知识库路由逻辑，用于调试路由策略")
    @PostMapping
    public Map<String, Object> route(@RequestBody KBRouteRequest request) {
        Map<String, Object> result = new HashMap<>();
        try {
            log.info("知识库路由测试: query={}", request.getQuery());
            KBRouteResponse response = kbRouteService.route(request);
            result.put("success", true);
            result.put("query", response.getQuery());
            result.put("userRole", response.getUserRole());
            result.put("userDepartment", response.getUserDepartment());
            result.put("targetCollections", response.getTargetCollections());
            result.put("intent", response.getIntent());
        } catch (Exception e) {
            log.error("知识库路由测试失败", e);
            result.put("success", false);
            result.put("message", "知识库路由测试失败: " + e.getMessage());
        }
        return result;
    }
}
