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

const BASE = 'quality_control/first_inspection/first_inspection/'
const PROCESS_STEP_BASE = 'production_configuration/technology_model/technology_flow_workingsubclass/'

function apiParams (data = {}, method = 'get.setting.list', platform = 'api') {
  return { method, platform, ...data }
}

export function fetchFirstArticleInspectionConfigurationList (data = {}) {
  return request({
    url: BASE + 'list',
    method: 'post',
    data: apiParams(data, 'get.setting.list', 'api')
  })
}

export function createFirstArticleInspectionConfiguration (data = {}) {
  return request({
    url: BASE + 'add',
    method: 'post',
    data: apiParams(data, 'add.setting', 'admin')
  })
}

export function editFirstArticleInspectionConfiguration (data = {}) {
  return request({
    url: BASE + 'update',
    method: 'post',
    data: apiParams(data, 'set.setting', 'admin')
  })
}

export function deleteFirstArticleInspectionConfiguration (data = {}) {
  return request({
    url: BASE + 'delete',
    method: 'post',
    data: apiParams(data, 'del.setting.list', 'admin')
  })
}

export function getQualityCategoryAll (data = {}) {
  return request({
    url: BASE + 'category/all',
    method: 'post',
    data: apiParams(data, 'get.quality.category.all', 'api')
  })
}

export function getWorkingsubclassAll (data = {}) {
  return request({
    url: PROCESS_STEP_BASE + 'all',
    method: 'get',
    params: {
      method: 'production_configuration_technology_model_technology_flow_workingsubclass_all',
      platform: 'background',
      ...data
    }
  })
}

export function fetchSettingItemList (data = {}) {
  return request({
    url: BASE + 'item/list',
    method: 'post',
    data: apiParams(data, 'get.setting.item.list', 'api')
  })
}

export function createSettingItem (data = {}) {
  return request({
    url: BASE + 'item/add',
    method: 'post',
    data: apiParams(data, 'add.setting.item', 'admin')
  })
}

export function editSettingItem (data = {}) {
  return request({
    url: BASE + 'item/update',
    method: 'post',
    data: apiParams(data, 'set.setting.item', 'admin')
  })
}

export function deleteSettingItem (data = {}) {
  return request({
    url: BASE + 'item/delete',
    method: 'post',
    data: apiParams(data, 'del.setting.item', 'admin')
  })
}
