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

// 数据集查询参数
export interface DatasetQueryParams {
	keyword?: string;
	status?: string;
	pageNum: number;
	pageSize: number;
}

// 创建知识库参数
export interface CreateDatasetParams {
	name: string; // 必传
	description?: string; // 可选
}

// 更新知识库参数
export interface UpdateDatasetParams {
	id: string; // 必传
	name?: string; // 可选
	description?: string; // 可选
}

// 数据集信息
export interface DatasetInfo {
	id?: string;
	name: string;
	description?: string;
	type: string; // text, qa, table
	documentCount?: number;
	charCount?: number;
	status: string; // enable, disable
	embeddingModel?: string;
	createdAt?: string;
	updatedAt?: string;
}

// 获取数据集列表
export function listDatasets(params: DatasetQueryParams) {
	return newService({
		url: '/rag-knowledge/knowledge/listKnowledge',
		method: 'get',
		params,
	});
}

// 获取数据集详情
export function getDataset(id: string) {
	return newService({
		url: '/knowledge/dataset/detail',
		method: 'get',
		params: { id },
	});
}

// 创建数据集（简化版）
export function createKnowledgeBase(data: CreateDatasetParams) {
	return newService({
		url: '/rag-knowledge/knowledge/createKnowledge',
		method: 'post',
		data,
	});
}

// 创建数据集（完整版）
export function createDataset(data: DatasetInfo) {
	return newService({
		url: '/knowledge/dataset/create',
		method: 'post',
		data,
	});
}

// 更新知识库（简化版）
export function updateKnowledgeBase(data: UpdateDatasetParams) {
	return newService({
		url: '/rag-knowledge/knowledge/updateKnowledge',
		method: 'put',
		data,
	});
}

// 更新数据集（完整版）
export function updateDataset(data: DatasetInfo) {
	return newService({
		url: '/knowledge/dataset/update',
		method: 'put',
		data,
	});
}

// 删除数据集
export function deleteDataset(id: string) {
	return newService({
		url: '/rag-knowledge/knowledge/deleteKnowledge',
		method: 'delete',
		params: { id },
	});
}

// 更新数据集状态
export function updateDatasetStatus(data: { id: string; status: string }) {
	return newService({
		url: '/knowledge/dataset/updateStatus',
		method: 'put',
		data,
	});
}
