import request from '@/utils/request';
import type {
  EmsActionResponse,
  EmsDetailResponse,
  EmsDynamicColumn,
  EmsId,
  EmsIdParam,
  EmsListResponse,
  EmsQuery,
  SparePartsInventoryExportVO,
  SparePartsInventoryVO
} from '../types';

// 查询备件库记录主列表
export function listSparePartsInventory(query?: EmsQuery): Promise<EmsListResponse<SparePartsInventoryVO>> {
  return request({
    url: '/ems/info/sparePartsInventory/list',
    method: 'get',
    params: query
  });
}

// 查询备件库记录主列表（包含动态列）
export function listSparePartsInventoryWithDynamicColumns(query?: EmsQuery): Promise<EmsListResponse<SparePartsInventoryExportVO>> {
  return request({
    url: '/ems/info/sparePartsInventory/listWithDynamicColumns',
    method: 'get',
    params: query
  });
}

// 查询备件库记录主详细
export function getSparePartsInventory(objid: EmsId): Promise<EmsDetailResponse<SparePartsInventoryVO>> {
  return request({
    url: '/ems/info/sparePartsInventory/' + objid,
    method: 'get'
  });
}

// 查询备件库记录主详细（包含动态列）
export function getSparePartsInventoryWithDynamicColumns(objid: EmsId): Promise<EmsDetailResponse<SparePartsInventoryExportVO>> {
  return request({
    url: '/ems/info/sparePartsInventory/withDynamicColumns/' + objid,
    method: 'get'
  });
}

// 新增备件库记录主
export function addSparePartsInventory(data: SparePartsInventoryVO): Promise<EmsActionResponse<SparePartsInventoryVO>> {
  return request({
    url: '/ems/info/sparePartsInventory',
    method: 'post',
    data: data
  });
}

// 新增备件库记录主（包含动态列）
export function addSparePartsInventoryWithDynamicColumns(data: SparePartsInventoryExportVO): Promise<EmsActionResponse<SparePartsInventoryExportVO>> {
  return request({
    url: '/ems/info/sparePartsInventory/withDynamicColumns',
    method: 'post',
    data: data
  });
}

// 修改备件库记录主
export function updateSparePartsInventory(data: SparePartsInventoryVO): Promise<EmsActionResponse<SparePartsInventoryVO>> {
  return request({
    url: '/ems/info/sparePartsInventory',
    method: 'put',
    data: data
  });
}

// 修改备件库记录主（包含动态列）
export function updateSparePartsInventoryWithDynamicColumns(
  data: SparePartsInventoryExportVO
): Promise<EmsActionResponse<SparePartsInventoryExportVO>> {
  return request({
    url: '/ems/info/sparePartsInventory/withDynamicColumns',
    method: 'put',
    data: data
  });
}

// 删除备件库记录主
export function delSparePartsInventory(objid: EmsIdParam): Promise<EmsActionResponse> {
  return request({
    url: '/ems/info/sparePartsInventory/' + objid,
    method: 'delete'
  });
}

// 获取所有动态列名
export function getDynamicColumns(): Promise<EmsDetailResponse<EmsDynamicColumn[]>> {
  return request({
    url: '/ems/info/sparePartsInventory/dynamicColumns',
    method: 'get'
  });
}
