import { getCubePlatformMeta } from './get-cube-platform-meta';
import { normalizeViewsResponse } from '../url/manual-biz-view-config-urls';
import { readTableViewFromComponents, loadUserCubeConfigFromPlatform, } from './process-user-cube-config';
const EMPTY_VIEWS = { views: {}, viewOrder: [] };
/**
 * 源码未配业务 URL：getList → 按 tableId 读 `components[].config.tableView` → `ViewsData`。
 */
export async function fetchViewsFromCube(tableId, bizRequestConfig) {
    if (!tableId) {
        return { views: EMPTY_VIEWS, userCubeConfigRowId: '' };
    }
    const meta = getCubePlatformMeta(tableId, bizRequestConfig);
    if (!meta) {
        return { views: EMPTY_VIEWS, userCubeConfigRowId: '' };
    }
    try {
        const { userCubeConfig, userCubeConfigRowId } = await loadUserCubeConfigFromPlatform(meta, bizRequestConfig);
        const views = normalizeViewsResponse(readTableViewFromComponents(userCubeConfig.components, tableId));
        return { views, userCubeConfigRowId };
    }
    catch {
        return { views: EMPTY_VIEWS, userCubeConfigRowId: '' };
    }
}
