import { request } from '@/utils/request'

// 设备操作日志 类型定义
export interface DeviceOperationLog {
    id?: number

    assingWorkId?: number

    userId?: number

    deviceId?: number

    source?: number

    operationType?: number

    createTime?:  string

}

// 设备操作日志 API
export const deviceOperationLogApi = {
    // 分页查询
    page(params: { page: number; pageSize: number; deviceId?: number; operationType?: number;userId?: number }) {
        return request({ url: '/terminal/operation/page', method: 'get', params })
    },

    // 获取详情
    detail(id:  string) {
        return request({ url: `/biz/deviceOperationLog/${id}`, method: 'get' })
    },

    // 新增
    create(data: DeviceOperationLog) {
        return request({ url: '/biz/deviceOperationLog', method: 'post', data })
    },

    // 修改
    update(data: DeviceOperationLog) {
        return request({ url: '/biz/deviceOperationLog', method: 'put', data })
    },

    // 删除
    delete(ids:  string[]) {
        return request({ url: `/biz/deviceOperationLog/${ids.join(',')}`, method: 'delete' })
    },

    // 导出
    export(params?: { ids?:  string[]; id?: number }) {
        const p: Record<string, any> = {}
        if (params?.ids?.length) p.ids = params.ids.join(',')
        if (params?.id !== undefined && params?.id !== null) p.id = params.id
        return request({ url: `/biz/deviceOperationLog/export`, method: 'get', params: p, responseType: 'blob' })
    },

    // 导入
    importData(file: File) {
        const formData = new FormData()
        formData.append('file', file)
        return request<{ success: number; fail: number; errors: string[] }>({
            url: `/biz/deviceOperationLog/import`,
            method: 'post',
            data: formData,
            headers: { 'Content-Type': 'multipart/form-data' }
        })
    },

    // 下载导入模板
    downloadTemplate() {
        return request({ url: `/biz/deviceOperationLog/template`, method: 'get', responseType: 'blob' })
    }
}