package com.infoepoch.pms.agent.platform.agent.application;

import com.infoepoch.pms.agent.platform.agent.adapter.out.submit.HttpSubmitStrategy;
import com.infoepoch.pms.agent.platform.agent.application.dto.AgentSubmitCommand;
import com.infoepoch.pms.agent.platform.agent.application.dto.AgentSubmitResult;
import com.infoepoch.pms.agent.platform.agent.domain.Agent;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 智能体提交服务。
 */
@Service
@RequiredArgsConstructor
public class AgentSubmitService {

    private final HttpSubmitStrategy httpSubmitStrategy;

    /**
     * 将智能体和表单字段映射为提交命令，并委托给 HTTP 提交策略执行。
     *
     * @param agent  智能体实体
     * @param fields 提交字段
     * @return 提交结果
     */
    public AgentSubmitResult submit(Agent agent, Map<String, Object> fields) {
        AgentSubmitCommand command = new AgentSubmitCommand(
                agent.getId(),
                agent.getName(),
                agent.getSubmitUrl(),
                fields
        );
        return httpSubmitStrategy.submit(command);
    }
}
