import { request } from '@/api/_service'
import qs from 'qs'

const BASE = 'system_settings/organization/production_team_manage/'
const MEMBER_BASE = 'system_settings/organization/production_members_manage/'

function params (method, data = {}) {
  return { method: `system_settings_organization_production_team_manage_${method}`, platform: 'background', ...data }
}

function memberParams (method, data = {}) {
  return { method: `system_settings_organization_production_members_manage_${method}`, platform: 'background', ...data }
}

function stringifyParams (method, data = {}) {
  return qs.stringify(params(method, data), { arrayFormat: 'brackets', allowDots: true, encode: false })
}

export function getTeamAll (data) { return request({ url: BASE + 'all', method: 'get', params: params('all', data) }) }
export function getTeamList (data) { return request({ url: BASE + 'list?' + stringifyParams('list', data), method: 'get', params: {} }) }
export function createTeam (data) { return request({ url: BASE + 'create', method: 'post', data: params('create', data) }) }
export function editTeam (data) { return request({ url: BASE + 'edit', method: 'put', data: params('edit', data) }) }
export function deleteTeam (data) { return request({ url: BASE + 'delete', method: 'delete', data: params('delete', data) }) }
export function getTeamImportTemplate (data) { return request({ url: BASE + 'get_import_template', method: 'post', responseType: 'blob', data: params('get_import_template', data) }) }
export function importTeamData (data) { return request({ url: BASE + 'data_import', method: 'post', data: params('data_import', data) }) }
export function exportTeamTask (data) { return request({ url: BASE + 'data_export_task', method: 'post', data: params('data_export_task', data) }) }

export function getTeamMemberList (data) { return request({ url: MEMBER_BASE + 'list', method: 'get', params: memberParams('list', data) }) }
export function deleteTeamMember (data) { return request({ url: MEMBER_BASE + 'delete', method: 'delete', data: memberParams('delete', data) }) }
