package com.pavis.admin.controller.aigc;

import com.pavis.admin.aigc.core.agent.planner.PlanContext;
import com.pavis.admin.aigc.model.query.AgentPlanQuery;
import com.pavis.admin.aigc.model.req.AgentPlanReq;
import com.pavis.admin.aigc.model.resp.AgentPlanDetailResp;
import com.pavis.admin.aigc.model.resp.AgentPlanResp;
import com.pavis.admin.aigc.service.AgentPlanService;
import com.pavis.admin.common.controller.BaseController;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
import top.continew.starter.extension.crud.enums.Api;

import java.util.Map;

/**
 * 智能体规划记录管理 API
 *
 * @author semi
 * @since 2025/05/28 16:59
 */
@Tag(name = "智能体规划记录管理 API")
@RestController
@CrudRequestMapping(value = "/aigc/agentPlan", api = {Api.PAGE, Api.GET, Api.CREATE, Api.UPDATE, Api.DELETE, Api.EXPORT})
public class AgentPlanController extends BaseController<AgentPlanService, AgentPlanResp, AgentPlanDetailResp, AgentPlanQuery, AgentPlanReq> {

    @Autowired
    private AgentPlanService agentPlanService;

    /**
     * 生成计划
     *
     * @param request 用户请求JSON信息
     * @return 计划上下文信息
     */
    @PostMapping("/generate")
    public PlanContext generatePlan(@RequestBody Map<String, Object> request) {
        Long conversationId = (Long) request.get("conversationId");
        Long messageId = (Long) request.get("messageId");
        Long planId = (Long) request.get("planId");
        String userMessage = (String) request.get("userMessage");
        PlanContext context = new PlanContext();
        context.setConversationId(conversationId);
        context.setMessageId(messageId);
        context.setPlanId(planId);
        context.setUserMessage(userMessage);
        return agentPlanService.createPlan(context);
    }

}