import request from '@/router/axios';
import axios from 'axios'

export const getList =
    (current, size, params, companyId) => {
      return request({
        url: '/api/jobslink-api/tenant/trade/base/tenant/find',
        method: 'get',
        params: {...params, current, size, companyId}
      })
    }

export const getTradeDic =
    (req) => {
      const url = '/api/jobslink-api/tenant/trade/base/find'
      if (req) {
        return request({
          url,
          method: 'get',
        })
      }
      else {
        return url
      }
    }

export const excelImport =
    (companyId, tenantId, isCovered) => {
      return `/api/jobslink-api/tenant/trade/base/excel-import?companyId=${
          companyId}&tenantId=${tenantId}&isCovered=${isCovered}`
    }


function updateTrade(data) {
  return request(
      {url: '/api/jobslink-api/tenant/trade/base/update', method: 'post', data})
}

function updateWorkTypes(data) {
  return request(
      {url: '/api/jobslink-api/tenant/worktypes/base/update', method: 'post', data})
}

function updateSkill(data) {
  return request(
      {url: '/api/jobslink-api/tenant/skills/base/update', method: 'post', data})
}

export const update =
    (trade, worktypes, skill) => {
      return new Promise(function(resolve, reject) {
        axios
            .all([
              updateTrade(trade), updateWorkTypes(worktypes), updateSkill(skill)
            ])
            .then(axios.spread(resolve), reject)
      })
    }

export const remove = (ids) => {
  return request({
    url: '/api/jobslink-api/tenant/trade/base/remove',
    method: 'post',
    params: {ids}
  })
}
