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

const BASE = 'system_settings/organization/production_shift_management/'

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

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

export function getShiftAll (data) { return request({ url: BASE + 'all', method: 'get', params: params('all', data) }) }
export function getShiftList (data) { return request({ url: BASE + 'list?' + stringifyParams('list', data), method: 'get', params: {} }) }
export function createShift (data) { return request({ url: BASE + 'create', method: 'post', data: params('create', data) }) }
export function editShift (data) { return request({ url: BASE + 'edit', method: 'put', data: params('edit', data) }) }
export function deleteShift (data) { return request({ url: BASE + 'delete', method: 'delete', data: params('delete', data) }) }
export function getShiftImportTemplate (data) { return request({ url: BASE + 'get_import_template', method: 'post', responseType: 'blob', data: params('get_import_template', data) }) }
export function importShiftData (data) { return request({ url: BASE + 'data_import', method: 'post', data: params('data_import', data) }) }
export function exportShiftTask (data) { return request({ url: BASE + 'data_export_task', method: 'post', data: params('data_export_task', data) }) }
export function getShiftCalendarByDateRange (data) { return request({ url: BASE + 'get_shift_by_date_range', method: 'get', params: params('get_shift_by_date_range', data) }) }
