import request from '@/utils/request'

export const workflowExecApi = {
  start: (workflowId, contactId, initVariables) => {
    return request({
      url: '/workflow/lobster-exec/start',
      method: 'post',
      params: { workflowId, contactId },
      data: initVariables
    })
  },
  executeNextNode: (instanceId, customerReply) => {
    return request({
      url: '/workflow/lobster-exec/next-node',
      method: 'post',
      params: { instanceId, customerReply }
    })
  },
  pause: (instanceId) => {
    return request({ url: `/workflow/lobster-exec/pause/${instanceId}`, method: 'post' })
  },
  resume: (instanceId) => {
    return request({ url: `/workflow/lobster-exec/resume/${instanceId}`, method: 'post' })
  },
  terminate: (instanceId, reason) => {
    return request({
      url: `/workflow/lobster-exec/terminate/${instanceId}`,
      method: 'post',
      params: { reason }
    })
  },
  getInstanceState: (instanceId) => {
    return request({ url: `/workflow/lobster-exec/instance/${instanceId}`, method: 'get' })
  },
  listInstances: (workflowId) => {
    return request({
      url: '/workflow/lobster-exec/instance/list',
      method: 'get',
      params: { workflowId }
    })
  },
  getNodeLogs: (instanceId) => {
    return request({ url: `/workflow/lobster-exec/node-logs/${instanceId}`, method: 'get' })
  },
  detectTakeover: (customerMessage, context) => {
    return request({
      url: '/workflow/lobster-exec/takeover-detect',
      method: 'post',
      params: { customerMessage, context }
    })
  },
  complianceCheck: (content) => {
    return request({
      url: '/workflow/lobster-exec/compliance-check',
      method: 'post',
      params: { content }
    })
  },
  getComplianceRules: () => {
    return request({ url: '/workflow/lobster-exec/compliance-rules', method: 'get' })
  },
  addComplianceRule: (data) => {
    return request({ url: '/workflow/lobster-exec/compliance-rule', method: 'post', data })
  },
  updateComplianceRule: (id, data) => {
    return request({ url: `/workflow/lobster-exec/compliance-rule/${id}`, method: 'put', data })
  },
  deleteComplianceRule: (id) => {
    return request({ url: `/workflow/lobster-exec/compliance-rule/${id}`, method: 'delete' })
  }
}
