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

const BASE = 'planning_production/produce/change_battery_process/'

function apiParams (method, data = {}) {
  return {
    method,
    platform: 'background',
    ...data
  }
}

function stringifyLegacyProcessOptions (data = {}) {
  const params = apiParams('planning_production_produce_change_battery_process_change', data)
  if (Array.isArray(params.processOptions)) {
    params.processOptions = params.processOptions.map(item => {
      return typeof item === 'string' ? item : JSON.stringify(item)
    })
  }
  return qs.stringify(params, { arrayFormat: 'brackets', allowDots: true, encode: false })
}

export function verifyBatteryProcessInfo (data) {
  return request({
    url: BASE + 'verify',
    method: 'get',
    params: apiParams('planning_production_produce_change_battery_process_verify', data)
  })
}

export function changeBatteryProcess (data) {
  return request({
    url: BASE + 'change?' + stringifyLegacyProcessOptions(data),
    method: 'get',
    params: {}
  })
}
