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

const BASE = 'production_configuration/matetial_model/bom/'
const RELATION_BASE = 'production_configuration/matetial_model/bom_relationship/'

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

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

export function getBomAll (data) {
  return request({ url: BASE + 'all', method: 'get', params: apiParams('all', data) })
}

export function getBomList (data) {
  return request({ url: BASE + 'list', method: 'get', params: apiParams('list', data) })
}

export function createBom (data) {
  return request({ url: BASE + 'create', method: 'post', data: apiParams('create', data) })
}

export function editBom (data) {
  return request({ url: BASE + 'edit', method: 'put', data: apiParams('edit', data) })
}

export function deleteBom (data) {
  return request({ url: BASE + 'delete', method: 'delete', data: apiParams('delete', data) })
}

export function getBomRelationshipList (data) {
  return request({ url: RELATION_BASE + 'list', method: 'get', params: relationApiParams('list', data) })
}

export function createBomRelationship (data) {
  return request({ url: RELATION_BASE + 'create', method: 'post', data: relationApiParams('create', data) })
}

export function editBomRelationship (data) {
  return request({ url: RELATION_BASE + 'edit', method: 'put', data: relationApiParams('edit', data) })
}

export function deleteBomRelationship (data) {
  return request({ url: RELATION_BASE + 'delete', method: 'delete', data: relationApiParams('delete', data) })
}
