import { defHttp } from '#/api/request';

export interface DevApprovalState {
  enabled: boolean;
  nodeName?: string;
  operatorId?: string;
  problems: string[];
  status: 'ADVANCED' | 'BLOCKED' | 'PASSED' | 'READY';
}

export function inspectDevApproval(taskId: string) {
  return defHttp.get<{ data: DevApprovalState }>({ url: `/api/workflow/devApproval/${encodeURIComponent(taskId)}` }, { errorMessageMode: 'none' });
}

export interface DevApprovalProgress {
  completed: number;
  message?: string;
  nodeName?: string;
  runId?: string;
  status: 'BLOCKED' | 'FAILED' | 'IDLE' | 'PASSED' | 'RUNNING' | 'STOPPED' | 'STOPPING';
}

export function startDevApprovalRun(taskId: string, signId: string) {
  return defHttp.post<{ data: DevApprovalProgress }>(
    { url: `/api/workflow/devApproval/${encodeURIComponent(taskId)}/run`, data: { signId } },
    { errorMessageMode: 'none' },
  );
}

export function getDevApprovalRun(taskId: string) {
  return defHttp.get<{ data: DevApprovalProgress }>({ url: `/api/workflow/devApproval/${encodeURIComponent(taskId)}/run` }, { errorMessageMode: 'none' });
}

export function stopDevApprovalRun(taskId: string, runId: string) {
  return defHttp.post<{ data: DevApprovalProgress }>(
    { url: `/api/workflow/devApproval/${encodeURIComponent(taskId)}/run/stop`, data: { runId } },
    { errorMessageMode: 'none' },
  );
}
