import apiService from './api.service' export interface WorkflowConditionDto { compareColumn: string compareOperator: string compareValue: number } export interface CompareOutcomeDto { label: string targetId?: string | null conditions: WorkflowConditionDto[] } export interface WorkflowCriteriaDto { id: string listFormCode: string nodeId: string kind: string title: string compareColumn: string compareOperator: string compareValue: number approver: string nextOnStart?: string | null nextOnTrue?: string | null nextOnFalse?: string | null nextOnApprove?: string | null nextOnReject?: string | null positionX: number positionY: number compareOutcomes: CompareOutcomeDto[] } export interface WorkflowCriteriasDto { criteria: WorkflowCriteriaDto[] } export interface WorkflowRunResultDto { keys: unknown[] currentNodeId?: string | null currentNodeTitle?: string | null currentNodeKind?: string | null waitingApproval: boolean completed: boolean } export type SaveCriteriaInput = Omit, 'id'> & { id?: string | null listFormCode: string } const baseUrl = '/api/app/list-form-workflow' export const workflowService = { async getCriteria(listFormCode?: string) { const response = await apiService.fetchData({ method: 'GET', url: `${baseUrl}/criteria`, params: { listFormCode }, }) return response.data }, async saveCriteria(payload: SaveCriteriaInput) { const response = await apiService.fetchData({ method: 'POST', url: `${baseUrl}/criteria`, data: payload, }) return response.data }, async deleteCriteria(id: string) { await apiService.fetchData({ method: 'DELETE', url: `${baseUrl}/criteria/${id}`, }) }, async resetDemo(listFormCode?: string) { const response = await apiService.fetchData({ method: 'POST', url: `${baseUrl}/reset-demo`, params: { listFormCode }, }) return response.data }, async startWorkflow(listFormCode: string, keys: unknown[]) { const response = await apiService.fetchData({ method: 'POST', url: `${baseUrl}/start`, data: { listFormCode, keys }, }) return response.data }, async decideWorkflow( listFormCode: string, keys: unknown[], approved: boolean, note?: string, currentNodeId?: string, ) { const response = await apiService.fetchData({ method: 'POST', url: `${baseUrl}/decision`, data: { listFormCode, keys, approved, note, currentNodeId }, }) return response.data }, }