import { api } from './http' import type { WorkflowDefinition, WorkflowExecutionDetail, WorkflowExecutionRecord, WorkflowExecutionResult } from '@/types/workflow' export const workflowApi = { create: async (wf: WorkflowDefinition): Promise => { const res = await api.post('/api/workflows', wf) return res.data }, update: async (id: string, wf: WorkflowDefinition): Promise => { const res = await api.put(`/api/workflows/${id}`, wf) return res.data }, save: async (wf: WorkflowDefinition): Promise => { return wf.id ? workflowApi.update(wf.id, wf) : workflowApi.create(wf) }, getById: async (id: string): Promise => { const res = await api.get(`/api/workflows/${id}`) return res.data }, list: async (status?: string, page = 1, size = 10): Promise<{ items: WorkflowDefinition[]; page: number; size: number; total: number }> => { const res = await api.get('/api/workflows', { params: { status, page, size } }) return res.data }, remove: async (id: string): Promise => { await api.delete(`/api/workflows/${id}`) }, execute: async (id: string, input: Record): Promise => { const res = await api.post(`/api/workflows/${id}/execute`, { input }) return res.data }, getExecutions: async (id: string, page = 1, size = 10): Promise<{ items: WorkflowExecutionRecord[]; page: number; size: number; total: number }> => { const res = await api.get(`/api/workflows/${id}/executions`, { params: { page, size } }) return res.data }, getExecutionDetail: async (executionId: string): Promise => { const res = await api.get(`/api/workflows/executions/${executionId}`) return res.data }, }