import { get, post } from '@/utils/request'
import type {
  IBaseResponse,
  IPageResponse,
  IListResponse,
  BaseResponse,
  MachineDTO,
  MachineAddRequest,
  MachineUpdateRequest,
  MachineListRequest
} from '@/types'

// 获取机器列表 (分页)
export function listMachines(params?: MachineListRequest): Promise<IPageResponse<MachineDTO>> {
  return post('/admin/machines/list', params || {})
}

// 获取机器列表 (全部，不分页)
export function listAllMachines(): Promise<IListResponse<MachineDTO>> {
  return get('/admin/machines/listAll')
}

// 获取机器详情
export function getMachine(id: number): Promise<IBaseResponse<MachineDTO>> {
  return get('/admin/machines/detail', { id })
}

// 添加机器
export function addMachine(data: MachineAddRequest): Promise<IBaseResponse<MachineDTO>> {
  return post('/admin/machines/add', data)
}

// 更新机器
export function updateMachine(data: MachineUpdateRequest): Promise<IBaseResponse<MachineDTO>> {
  return post('/admin/machines/update', data)
}

// 删除机器
export function deleteMachine(id: number): Promise<BaseResponse> {
  return post('/admin/machines/delete', undefined, {
    params: { id }
  })
}
