"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const joi_1 = __importDefault(require("joi"));
const DriverDependencies_1 = __importDefault(require("./DriverDependencies"));
const schemaQueueOptions = joi_1.default.object().strict(true).keys({
    concurrency: joi_1.default.number().min(1).integer(),
    continueWaitTimeout: joi_1.default.number().min(0).max(90).integer(),
    executionTimeout: joi_1.default.number().min(0).integer(),
    orphanedTimeout: joi_1.default.number().min(0).integer(),
    heartBeatInterval: joi_1.default.number().min(0).integer(),
    sendProcessMessageFn: joi_1.default.func(),
    sendCancelMessageFn: joi_1.default.func(),
});
const jwtOptions = joi_1.default.object().strict(true).keys({
    // JWK options
    jwkRetry: joi_1.default.number().min(1).max(5).integer(),
    jwkDefaultExpire: joi_1.default.number().min(0),
    jwkUrl: joi_1.default.alternatives().try(joi_1.default.string(), joi_1.default.func()),
    jwkRefetchWindow: joi_1.default.number().min(0),
    // JWT options
    key: joi_1.default.string(),
    algorithms: joi_1.default.array().items(joi_1.default.string()),
    issuer: joi_1.default.array().items(joi_1.default.string()),
    audience: joi_1.default.string(),
    subject: joi_1.default.string(),
    claimsNamespace: joi_1.default.string(),
});
const corsOptions = joi_1.default.object().strict(true).keys({
    origin: joi_1.default.any(),
    methods: joi_1.default.any(),
    allowedHeaders: joi_1.default.any(),
    exposedHeaders: joi_1.default.any(),
    credentials: joi_1.default.bool(),
    maxAge: joi_1.default.number(),
    preflightContinue: joi_1.default.bool(),
    optionsSuccessStatus: joi_1.default.number(),
});
const dbTypes = joi_1.default.alternatives().try(joi_1.default.string().valid(...Object.keys(DriverDependencies_1.default)), joi_1.default.func());
const schemaOptions = joi_1.default.object().keys({
    // server CreateOptions
    webSockets: joi_1.default.boolean(),
    http: joi_1.default.object().strict(true).keys({
        cors: corsOptions,
    }),
    gracefulShutdown: joi_1.default.number().min(0).integer(),
    serverHeadersTimeout: joi_1.default.number(),
    serverKeepAliveTimeout: joi_1.default.number(),
    // Additional from WebSocketServerOptions
    processSubscriptionsInterval: joi_1.default.number(),
    webSocketsBasePath: joi_1.default.string(),
    // server-core CoreCreateOptions
    dbType: dbTypes,
    externalDbType: dbTypes,
    schemaPath: joi_1.default.string(),
    basePath: joi_1.default.string(),
    devServer: joi_1.default.boolean(),
    apiSecret: joi_1.default.string(),
    logger: joi_1.default.func(),
    // source
    dialectFactory: joi_1.default.func(),
    driverFactory: joi_1.default.func(),
    // external
    externalDialectFactory: joi_1.default.func(),
    externalDriverFactory: joi_1.default.func(),
    //
    cacheAndQueueDriver: joi_1.default.string().valid('cubestore', 'memory'),
    contextToAppId: joi_1.default.func(),
    contextToRoles: joi_1.default.func(),
    contextToOrchestratorId: joi_1.default.func(),
    contextToCubeStoreRouterId: joi_1.default.func(),
    contextToDataSourceId: joi_1.default.func(),
    contextToApiScopes: joi_1.default.func(),
    repositoryFactory: joi_1.default.func(),
    checkAuth: joi_1.default.func(),
    jwt: jwtOptions,
    queryTransformer: joi_1.default.func(),
    queryRewrite: joi_1.default.func(),
    preAggregationsSchema: joi_1.default.alternatives().try(joi_1.default.string(), joi_1.default.func()),
    schemaVersion: joi_1.default.func(),
    extendContext: joi_1.default.func(),
    // Scheduled refresh
    scheduledRefreshTimer: joi_1.default.alternatives().try(joi_1.default.boolean(), joi_1.default.number().min(0).integer()),
    scheduledRefreshTimeZones: joi_1.default.alternatives().try(joi_1.default.array().items(joi_1.default.string()), joi_1.default.func()),
    scheduledRefreshContexts: joi_1.default.func(),
    scheduledRefreshConcurrency: joi_1.default.number().min(1).integer(),
    scheduledRefreshBatchSize: joi_1.default.number().min(1).integer(),
    // Compiler cache
    compilerCacheSize: joi_1.default.number().min(0).integer(),
    updateCompilerCacheKeepAlive: joi_1.default.boolean(),
    maxCompilerCacheKeepAlive: joi_1.default.number().min(0).integer(),
    telemetry: joi_1.default.boolean(),
    allowUngroupedWithoutPrimaryKey: joi_1.default.boolean(),
    orchestratorOptions: joi_1.default.alternatives().try(joi_1.default.func(), joi_1.default.object().strict(true).keys({
        redisPrefix: joi_1.default.string().allow(''),
        continueWaitTimeout: joi_1.default.number().min(0).max(90).integer(),
        skipExternalCacheAndQueue: joi_1.default.boolean(),
        queryCacheOptions: joi_1.default.object().keys({
            refreshKeyRenewalThreshold: joi_1.default.number().min(0).integer(),
            backgroundRenew: joi_1.default.boolean(),
            queueOptions: schemaQueueOptions,
            externalQueueOptions: schemaQueueOptions
        }),
        preAggregationsOptions: {
            queueOptions: schemaQueueOptions,
            externalRefresh: joi_1.default.boolean(),
            maxPartitions: joi_1.default.number(),
        },
        rollupOnlyMode: joi_1.default.boolean(),
        testConnectionTimeout: joi_1.default.number().min(0).integer(),
    })),
    allowJsDuplicatePropsInSchema: joi_1.default.boolean(),
    dashboardAppPath: joi_1.default.string(),
    dashboardAppPort: joi_1.default.number(),
    sqlCache: joi_1.default.boolean(),
    livePreview: joi_1.default.boolean(),
    // SQL API
    sqlPort: joi_1.default.number(),
    pgSqlPort: joi_1.default.number(),
    gatewayPort: joi_1.default.number(),
    sqlSuperUser: joi_1.default.string(),
    checkSqlAuth: joi_1.default.func(),
    canSwitchSqlUser: joi_1.default.func(),
    sqlUser: joi_1.default.string(),
    sqlPassword: joi_1.default.string(),
    semanticLayerSync: joi_1.default.func(),
    // Additional system flags
    serverless: joi_1.default.boolean(),
    allowNodeRequire: joi_1.default.boolean(),
    fastReload: joi_1.default.boolean(),
});
exports.default = (options) => {
    const { error } = schemaOptions.validate(options, { abortEarly: false });
    if (error) {
        throw new Error(`Invalid cube-server-core options: ${error.message || error.toString()}`);
    }
};
//# sourceMappingURL=optionsValidate.js.map