import http from '@/utils/http'
import type * as T from '@/types/equipment.d'

const BASE_URL = '/equipment'

/** @desc 分页查询设备列表 */
export function pageEquipment(query: T.EquipmentPageQuery) {
    return http.get<T.EquipmentResp[]>(`${BASE_URL}/page`, query)
}

/** @desc 查询设备列表 */
export function listEquipment(query?: T.EquipmentPageQuery) {
    return http.get<T.EquipmentResp[]>(`${BASE_URL}/list`, query)
}

/** @desc 查询设备详情 */
export function getEquipmentDetail(equipmentId: string) {
    return http.get<T.EquipmentResp>(`${BASE_URL}/detail/${equipmentId}`)
}

/** @desc 新增设备 */
export function createEquipment(data: T.EquipmentReq) {
    return http.post(`${BASE_URL}`, data)
}

/** @desc 更新设备 */
export function updateEquipment(equipmentId: string, data: T.EquipmentReq) {
    return http.put(`${BASE_URL}/${equipmentId}`, data)
}

/** @desc 删除设备 */
export function deleteEquipment(equipmentId: string) {
    return http.del(`${BASE_URL}/${equipmentId}`)
}

/** @desc 设备状态变更 */
export function changeEquipmentStatus(equipmentId: string, status: string) {
    return http.put(`${BASE_URL}/${equipmentId}/status`, { status })
}

/** @desc 设备分配 */
export function assignEquipment(equipmentId: string, userId: string) {
    return http.put(`${BASE_URL}/${equipmentId}/assign`, { userId })
}

/** @desc 设备归还 */
export function returnEquipment(equipmentId: string) {
    return http.put(`${BASE_URL}/${equipmentId}/return`)
}

// 导出设备采购 API
export * from './procurement'

// 设备盘库相关 API
/** @desc 分页查询设备盘库记录 */
export function pageEquipmentInventory(query: T.EquipmentPageQuery) {
    return http.get<T.EquipmentResp[]>(`${BASE_URL}/inventory/page`, query)
}

/** @desc 执行设备盘库 */
export function executeEquipmentInventory(equipmentId: string, inventoryResult: string, remark?: string) {
    return http.post(`${BASE_URL}/inventory/${equipmentId}`, null, {
        params: { inventoryResult, remark }
    })
}

/** @desc 批量执行设备盘库 */
export function batchExecuteEquipmentInventory(equipmentIds: string[], inventoryResult: string, remark?: string) {
    return http.post(`${BASE_URL}/inventory/batch`, null, {
        params: { equipmentIds, inventoryResult, remark }
    })
}