// ⚠️ 示例文件：仅用于接口调用演示，不参与生产运行。
// 文档接口使用示例
import { 
    createDocument, 
    CreateDocumentParams,
    updateDocument,
    UpdateDocumentParams,
    uploadDocument,
    deleteDocument,
    listDocuments,
    DocumentQueryParams
} from '/@/api/knowledge/document';

// 示例1：创建文档（JSON格式）
const createDocumentExample = async () => {
    const params: CreateDocumentParams = {
        KnowledgeId: 12345,        // 知识库ID，必传
        filePath: '/path/to/document.pdf', // 文件路径，必传
        fileSize: 1024000,        // 文件大小（字节），必传
        format: 'pdf',            // 文件格式，必传
        title: '产品使用手册'     // 文档标题，必传
    };
    
    try {
        const response = await createDocument(params);
        console.log('文档创建成功:', response.data);
        return response.data;
    } catch (error) {
        console.error('创建失败:', error);
        throw error;
    }
};

// 示例2：上传文档（FormData格式）
const uploadDocumentExample = async (file: File, knowledgeId: string) => {
    const formData = new FormData();
    formData.append('file', file);
    formData.append('datasetId', knowledgeId);
    
    try {
        const response = await uploadDocument(formData);
        console.log('文档上传成功:', response.data);
        return response.data;
    } catch (error) {
        console.error('上传失败:', error);
        throw error;
    }
};

// 示例3：获取文档列表
const getDocumentList = async (knowledgeId: string) => {
    const params: DocumentQueryParams = {
        datasetId: knowledgeId,
        pageNum: 1,
        pageSize: 10,
        keyword: '', // 可选搜索关键字
        status: '',  // 可选状态筛选
        fileType: '' // 可选文件类型筛选
    };
    
    try {
        const response = await listDocuments(params);
        console.log('文档列表:', response.data);
        return response.data;
    } catch (error) {
        console.error('获取列表失败:', error);
        throw error;
    }
};

// 示例4：更新文档
const updateDocumentExample = async () => {
    const params: UpdateDocumentParams = {
        id: '1234567890',        // 必传
        title: '更新后的文档标题' // 可选，只更新标题
    };
    
    try {
        const response = await updateDocument(params);
        console.log('文档更新成功:', response.data);
        return response.data;
    } catch (error) {
        console.error('更新失败:', error);
        throw error;
    }
};

// 示例5：完整更新文档
const updateDocumentFull = async () => {
    const params: UpdateDocumentParams = {
        id: '1234567890',        // 必传
        KnowledgeId: 67890,      // 可选
        filePath: '/new/path/document.pdf', // 可选
        fileSize: 2048000,       // 可选
        format: 'pdf',           // 可选
        title: '完全更新的文档'   // 可选
    };
    
    try {
        const response = await updateDocument(params);
        console.log('文档完整更新成功:', response.data);
        return response.data;
    } catch (error) {
        console.error('更新失败:', error);
        throw error;
    }
};

// 示例6：删除文档
const deleteDocumentExample = async (documentId: string) => {
    try {
        await deleteDocument(documentId);
        console.log('文档删除成功');
    } catch (error) {
        console.error('删除失败:', error);
        throw error;
    }
};

// 在Vue组件中使用
/*
import { ref } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { 
    createDocument, 
    CreateDocumentParams,
    uploadDocument,
    deleteDocument,
    listDocuments,
    DocumentQueryParams
} from '/@/api/knowledge/document';

export default defineComponent({
    setup() {
        const formData = ref<CreateDocumentParams>({
            KnowledgeId: 0,
            filePath: '',
            fileSize: 0,
            format: '',
            title: ''
        });
        
        const loading = ref(false);
        const documentList = ref([]);
        
        // 创建文档
        const handleCreate = async () => {
            // 验证必填字段
            if (!formData.value.KnowledgeId || !formData.value.filePath || 
                !formData.value.fileSize || !formData.value.format || !formData.value.title) {
                ElMessage.error('请填写所有必填字段');
                return;
            }
            
            loading.value = true;
            try {
                await createDocument(formData.value);
                ElMessage.success('文档创建成功');
                // 重置表单
                formData.value = {
                    KnowledgeId: 0,
                    filePath: '',
                    fileSize: 0,
                    format: '',
                    title: ''
                };
                // 刷新列表
                await getDocuments();
            } catch (error) {
                ElMessage.error('创建失败，请重试');
            } finally {
                loading.value = false;
            }
        };
        
        // 文件上传
        const handleFileUpload = async (event: Event, knowledgeId: string) => {
            const file = (event.target as HTMLInputElement).files?.[0];
            if (!file) return;
            
            const formData = new FormData();
            formData.append('file', file);
            formData.append('datasetId', knowledgeId);
            
            loading.value = true;
            try {
                await uploadDocument(formData);
                ElMessage.success('文档上传成功');
                await getDocuments();
            } catch (error) {
                ElMessage.error('上传失败，请重试');
            } finally {
                loading.value = false;
            }
        };
        
        // 删除文档
        const handleDelete = async (id: string) => {
            try {
                await ElMessageBox.confirm('确定要删除这个文档吗？', '提示', {
                    type: 'warning',
                });
                
                await deleteDocument(id);
                ElMessage.success('删除成功');
                await getDocuments();
            } catch (error) {
                if (error !== 'cancel') {
                    ElMessage.error('删除失败');
                }
            }
        };
        
        // 获取文档列表
        const getDocuments = async () => {
            try {
                const response = await listDocuments({
                    pageNum: 1,
                    pageSize: 10
                });
                documentList.value = response.data.list;
            } catch (error) {
                console.error('获取列表失败:', error);
            }
        };
        
        return {
            formData,
            loading,
            documentList,
            handleCreate,
            handleFileUpload,
            handleDelete,
            getDocuments
        };
    }
});
*/
