// 节点设计相关服务

import request from '@/utils/request';
import type {NodeDesignQuery, NodeDefinitionResponse, NodeDesignDataResponse} from './types';

const BASE_URL = '/api/v1/workflow/node-definition';

// 获取节点设计列表
export const getNodeDefinitions = (params: NodeDesignQuery) =>
    request.get<NodeDefinitionResponse>(`${BASE_URL}/page`, {params});

// 获取节点设计详情
export const getNodeDefinition = (id: number) =>
    request.get<NodeDefinitionResponse>(`${BASE_URL}/${id}`);


// 获取已定义的节点类型配置
export const getNodeDefinitionsDefined = () =>
    request.get<NodeDesignDataResponse[]>(`${BASE_URL}/defined`);

// 保存节点定义
export const saveNodeDefinition = (data: NodeDesignDataResponse) =>
    request.post<void>(`${BASE_URL}`, data);

export const updateNodeDefinition = (id: number, data: NodeDesignDataResponse) =>
    request.put<void>(`${BASE_URL}/${id}`, data);

/**
 * 删除节点定义
 * @param id 节点ID
 */
export const deleteNodeDefinition = (id: number) =>
    request.delete<void>(`${BASE_URL}/${id}`);
