package tech.easyflow.admin.controller.agent;

import tech.easyflow.agent.entity.Agent;
import tech.easyflow.agent.entity.AgentKnowledgeBinding;
import tech.easyflow.agent.entity.AgentSkillBinding;
import tech.easyflow.agent.entity.AgentToolBinding;

import java.util.List;

/**
 * Agent 设计器原子保存请求。
 *
 * <p>绑定变更标记由设计器基于加载后的稳定业务字段计算。服务端仍会执行权限、状态与幂等比较，
 * 标记为未变化的绑定不会进入查询、外部资源校验或整组重写流程。</p>
 */
public class AgentDraftSaveRequest {

    private Agent agent;
    private List<AgentToolBinding> toolBindings;
    private boolean replaceToolBindings;
    private List<AgentKnowledgeBinding> knowledgeBindings;
    private boolean replaceKnowledgeBindings;
    private List<AgentSkillBindingUpdateRequest.Binding> skillBindings;
    private boolean replaceSkillBindings;

    /** 创建空请求。 */
    public AgentDraftSaveRequest() {
    }

    /** @return Agent 草稿 */
    public Agent getAgent() {
        return agent;
    }

    /** @param agent Agent 草稿 */
    public void setAgent(Agent agent) {
        this.agent = agent;
    }

    /** @return 工具绑定 */
    public List<AgentToolBinding> getToolBindings() {
        return toolBindings;
    }

    /** @param toolBindings 工具绑定 */
    public void setToolBindings(List<AgentToolBinding> toolBindings) {
        this.toolBindings = toolBindings;
    }

    /** @return 是否替换工具绑定 */
    public boolean isReplaceToolBindings() {
        return replaceToolBindings;
    }

    /** @param replaceToolBindings 是否替换工具绑定 */
    public void setReplaceToolBindings(boolean replaceToolBindings) {
        this.replaceToolBindings = replaceToolBindings;
    }

    /** @return 知识库绑定 */
    public List<AgentKnowledgeBinding> getKnowledgeBindings() {
        return knowledgeBindings;
    }

    /** @param knowledgeBindings 知识库绑定 */
    public void setKnowledgeBindings(List<AgentKnowledgeBinding> knowledgeBindings) {
        this.knowledgeBindings = knowledgeBindings;
    }

    /** @return 是否替换知识库绑定 */
    public boolean isReplaceKnowledgeBindings() {
        return replaceKnowledgeBindings;
    }

    /** @param replaceKnowledgeBindings 是否替换知识库绑定 */
    public void setReplaceKnowledgeBindings(boolean replaceKnowledgeBindings) {
        this.replaceKnowledgeBindings = replaceKnowledgeBindings;
    }

    /** @return Skill 绑定 */
    public List<AgentSkillBindingUpdateRequest.Binding> getSkillBindings() {
        return skillBindings;
    }

    /** @param skillBindings Skill 绑定 */
    public void setSkillBindings(List<AgentSkillBindingUpdateRequest.Binding> skillBindings) {
        this.skillBindings = skillBindings;
    }

    /** @return 是否替换 Skill 绑定 */
    public boolean isReplaceSkillBindings() {
        return replaceSkillBindings;
    }

    /** @param replaceSkillBindings 是否替换 Skill 绑定 */
    public void setReplaceSkillBindings(boolean replaceSkillBindings) {
        this.replaceSkillBindings = replaceSkillBindings;
    }

    /**
     * 将 Skill 白名单引用转换为领域绑定。
     *
     * @return 最小 Skill 绑定列表
     */
    public List<AgentSkillBinding> toSkillBindings() {
        return skillBindings == null
                ? List.of() : skillBindings.stream().map(AgentSkillBindingUpdateRequest.Binding::toEntity).toList();
    }
}
