/**
 * Configuration validator utilities for Agent Constructor Configuration
 * Validates configuration values for correctness and security
 */
import { ConfigurationError, CONFIG_ERRORS, } from "../types/index.js";
export class ConfigValidator {
    /**
     * Validates gateway configuration
     * @param config - Configuration to validate
     * @throws ConfigurationError with descriptive message if invalid
     */
    static validateGatewayConfig(config) {
        // Validate API key if provided
        if (config.apiKey !== undefined) {
            if (typeof config.apiKey !== "string") {
                throw new ConfigurationError("API key must be a string if provided.", "apiKey", config.apiKey);
            }
        }
        // Validate base URL
        if (!config.baseURL || typeof config.baseURL !== "string") {
            throw new ConfigurationError(CONFIG_ERRORS.EMPTY_BASE_URL, "baseURL", config.baseURL);
        }
        if (config.baseURL.trim() === "") {
            throw new ConfigurationError(CONFIG_ERRORS.EMPTY_BASE_URL, "baseURL", config.baseURL);
        }
        // Basic URL format validation
        try {
            new URL(config.baseURL);
        }
        catch {
            throw new ConfigurationError(`Base URL must be a valid URL format. Received: ${config.baseURL}`, "baseURL", config.baseURL);
        }
    }
    /**
     * Validates token limit value
     * @param maxInputTokens - Token limit to validate
     * @throws ConfigurationError if invalid
     */
    static validateMaxInputTokens(maxInputTokens) {
        if (typeof maxInputTokens !== "number") {
            throw new ConfigurationError(CONFIG_ERRORS.INVALID_WAVE_MAX_INPUT_TOKENS, "maxInputTokens", maxInputTokens);
        }
        if (!Number.isInteger(maxInputTokens)) {
            throw new ConfigurationError(CONFIG_ERRORS.INVALID_WAVE_MAX_INPUT_TOKENS, "maxInputTokens", maxInputTokens);
        }
        if (maxInputTokens <= 0) {
            throw new ConfigurationError(CONFIG_ERRORS.INVALID_WAVE_MAX_INPUT_TOKENS, "maxInputTokens", maxInputTokens);
        }
    }
    /**
     * Validates model configuration (basic validation)
     * @param config - Model configuration object
     * @throws ConfigurationError if invalid
     */
    static validateModelConfig(config) {
        const { model, fastModel } = config;
        if (!model || typeof model !== "string" || model.trim() === "") {
            throw new ConfigurationError("Agent model must be a non-empty string.", "model", model);
        }
        if (!fastModel ||
            typeof fastModel !== "string" ||
            fastModel.trim() === "") {
            throw new ConfigurationError("Fast model must be a non-empty string.", "fastModel", fastModel);
        }
    }
}
/**
 * Static configuration validator instance
 * Implements ConfigurationValidator interface from types.ts
 */
export const configValidator = {
    validateGatewayConfig: ConfigValidator.validateGatewayConfig,
    validateMaxInputTokens: ConfigValidator.validateMaxInputTokens,
    validateModelConfig: (config) => ConfigValidator.validateModelConfig(config),
};
