import http from '@/utils/request'
export function getSystemConfigList (params = {}) {
  return http.post('/admin/system-config/list', { data: params })
}

export function deleteSystemConfig (params) {
  return http.post('/admin/system-config/delete', { data: params })
}

export function addSystemConfig (params) {
  return http.post('/admin/system-config/add', { data: params })
}

export function updateSystemConfig (params) {
  return http.post('/admin/system-config/update', { data: params })
}

export function getPayChannel () {
  return http.post('/admin/system-config/list', {
    data: {
      configKey: '',
      configDesc: ''
    }
  }).then(res => {
    let item = res.data.find(item => item.configKey === 'payChannel')
    return item?.configValue?.split(',') || []
  })
}

export function getCustomerType () {
  return http.post('/admin/system-config/list', {
    data: {
      configKey: '',
      configDesc: ''
    }
  }).then(res => {
    let item = res.data.find(item => item.configKey === 'customerType')
    return item?.configValue?.split(',') || []
  })
}

export function getTravelAgencyType () {
  return http.post('/admin/system-config/list', {
    data: {
      configKey: '',
      configDesc: ''
    }
  }).then(res => {
    let item = res.data.find(item => item.configKey === 'travel_agency_type')
    return item?.configValue?.split(',') || []
  })
}

export function getManualTicketCheckScenic () {
  /* 获取系统配置里的是否开启人工检票里选景点的功能 */
  return http.post('/admin/system-config/list', {
    data: {
      configKey: '',
      configDesc: ''
    }
  }).then(res => {
    let item = res.data.find(item => item.configKey === 'manual_ticket_check_scenic')
    console.log('系统配置里的人工检票是否开启景点选择：', JSON.stringify(item), 'Y/N:', item?.configValue)
    /* item.configValue.split(',') 为 [1] 这种数组, item.configValue为1或9 */
    return item?.configValue /* 1 or 0 */
  })
}
