import request from '../../../axios'
import { IBusiness } from './types'

export const baseDataList = () => {
  return request.get({ url: '/api/dynamicform/dynamicDataTable/findList' })
}

// 动态表单 - 业务表分类
export const tree = () => {
  return request.post({
    url: `/api/dynamicform/dynamicServiceTableClassify/findList`
  })
}
export const createBusinessType = (data) => {
  return request.post({ url: '/api/dynamicform/dynamicServiceTableClassify/create', data })
}
export const updateBusinessType = (data) => {
  return request.post({ url: '/api/dynamicform/dynamicServiceTableClassify/update', data })
}
export const findBusinessType = (leadServiceClassifyId: number) => {
  return request.get({
    url: `/api/dynamicform/dynamicServiceTableClassify/findById?leadServiceClassifyId=${leadServiceClassifyId}`
  })
}
export const delBusinessType = (data) => {
  return request.post({
    url: `/api/dynamicform/dynamicServiceTableClassify/deleteById`,
    data
  })
}
// 业务表
export const BusinessTableList = (data) => {
  return request.post({
    url: `/api/dynamicform/dynamicServiceTable/findListByPage`,
    data
  })
}
export const createBusinessTable = (data: IBusiness) => {
  return request.post({ url: '/api/dynamicform/dynamicServiceTable/create', data })
}
export const updateBusinessTable = (data: IBusiness) => {
  return request.post({ url: '/api/dynamicform/dynamicServiceTable/update', data })
}
export const findBusinessTable = (id: number | null) => {
  return request.get({
    url: `/api/dynamicform/dynamicServiceTable/findById?leadServiceTableId=${id}`
  })
}
export const delBusinessTable = (id: number) => {
  return request.post({
    url: '/api/dynamicform/dynamicServiceTable/deleteById',
    data: {
      id
    }
  })
}
// 字段配置
export const findFieldConfigById = (leadServiceTableId: number) => {
  return request.get({
    url: `/api/dynamicform/dynamicServiceTable/findFieldConfigById?leadServiceTableId=${leadServiceTableId}`
  })
}
export const updateFieldConfig = (data) => {
  return request.post({
    url: `/api/dynamicform/dynamicServiceTable/updateFieldConfig`,
    data
  })
}
// 查询业务字典接口
export const queryTypeList = () => {
  return request.get({
    url: `/api/sys/code/queryTypeList`
  })
}

// 查询字段
export const findFormById = (leadServiceTableId: number) => {
  return request.get({
    url: `/api/dynamicform/dynamicServiceTable/findFormById?leadServiceTableId=${leadServiceTableId}`
  })
}
