import request from '@/utils/request'

export interface DbItem {
  label: string;
  value: string;
  disabled?: boolean;
}

export interface dbResponse {
  code: number
  message: string
  result: DbItem[]
}



export interface SyncTables {
  createTime: string;
  taskId: string;
  taskName: string;
  sourceDbId: string;
  sourceTable: string;
  targetTable: string;
  isActive: string;
  lastSyncTime: string;
  updateTime: string;
  dbType: string;
  dbId: string;
  successRows: number;  
}


/** 获取数据库下拉列表 */
export const getDbList = async (): Promise<DbItem[]> => {
  const response = await request.get<dbResponse>('/Sys/data/getDbList')
  
  if (response.code !== 200) {
    console.error('获取数据失败:', response.message)
    throw new Error(`获取数据失败: ${response.message}`)
  }
  return response.result || []
}


export const getSyncTables = async (data: SyncTables): Promise<SyncTables[]> =>{
	const response = await request.get<SyncTables>('/Sys/data/getTableList', { params: data })
	if (response.code !== 200) {
	  console.error('获取数据失败:', response.message)
	  throw new Error(`获取数据失败: ${response.message}`)
	}
	return response.result || []
}