import request from '@/utils/request';

// /dm/struct/:id 获取数据模型结构
// /dm/:id   获取接口模型配置

// 导入表列表
export function getDbList(query: any) {
	return request({
		url: '/api/core/runtime/database/sql/tables',
		method: 'get',
		params: query,
	});
}

// 获取代码生成列表
export function getTableList(query: any) {
	return request({
		// url: '/api/develop/code/table/list',
		url: '/api/dm',
		method: 'get',
		params: query,
	});
}

// 获取表信息
export function getTableInfo(tableId: any) {
	return request({
		url: '/api/develop/code/table/info/' + tableId,
		// url: '/api/dm/struct/' + tableId,
		method: 'get',
	});
}

// 获取表字段信息
export function getTableColInfo(tableId: any) {
	return request({
		url: `/api/dm/struct/${tableId}?showAll=1`,
		method: 'get',
	});
}

// 获取表基础信息
export function getTableBasicInfo(tableId: any) {
	return request({
		url: '/api/dm/' + tableId,
		method: 'get',
	});
}

// 获取表信息
export function getTableInfoByName(query: any) {
	return request({
		url: '/api/develop/code/table/info/tableName',
		method: 'get',
		params: query,
	});
}
// 获取表树信息
export function getTableTree() {
	return request({
		url: '/api/dm/tables',
		method: 'get',
	});
}

// 导入表
export function insertTable(data: any) {
	return request({
		url: '/api/dm/import',
		method: 'post',
		data: data,
	});
}

// 修改代码列字段信息
// export function updateTable(id: any, data: any) {
// 	return request({
// 		// url: '/api/develop/code/table',
// 		url: '/api/dm/cols/' + id,
// 		method: 'put',
// 		data: data,
// 	});
// }
export function updateTable(id: any, data: any) {
	return request({
		url: `/api/dm/struct/${id}?showAll=1`,
		method: 'put',
		data: data,
	});
}

// 修改代码基本信息
export function updateBasicTable(data: any) {
	return request({
		url: '/api/dm/' + data.tableId,
		method: 'put',
		data: data,
	});
}

// 删除表
export function deleteTable(tableId: any) {
	return request({
		// url: '/api/develop/code/table/' + tableId,
		url: '/api/dm/' + tableId,
		method: 'delete',
	});
}

// 同步表数据
export function snycTable(tableId: any) {
	return request({
		url: '/api/dm/cols/sync/' + tableId,
		method: 'post',
	});
}

// 复制表
export function copyTable(tableId: any) {
	return request({
		url: '/api/dm/copy/' + tableId,
		method: 'post',
	});
}
