import type { RatesConfig } from './RatesConfig'; /** * Loads and validates CalOohPay configuration from file system. * * This module handles loading the optional `.caloohpay.json` configuration file * from the project root. If no config file exists, it gracefully falls back to * default rates, ensuring the application works out-of-the-box. * * @category Configuration * * @remarks * Configuration loading follows this priority: * 1. `.caloohpay.json` in current working directory * 2. `.caloohpay.json` in user's home directory * 3. Default rates from Constants.ts * * @example * ```typescript * import { ConfigLoader } from './config/ConfigLoader'; * * const loader = new ConfigLoader(); * const rates = loader.loadRates(); * * console.log(`Weekday rate: ${rates.weekdayRate}`); * console.log(`Weekend rate: ${rates.weekendRate}`); * ``` */ export declare class ConfigLoader { /** * Configuration file name to search for. * @private */ private static readonly CONFIG_FILENAME; /** * Loads compensation rates from config file or defaults. * * Attempts to load configuration from `.caloohpay.json` in the following locations: * 1. Current working directory (`process.cwd()`) * 2. User's home directory * * If no config file is found or parsing fails, returns default rates. * * @returns {RatesConfig} Validated compensation rates configuration * * @throws {Error} If config file exists but contains invalid rate values * * @remarks * Silent fallback behaviour: * - Missing config file → Use defaults (no error) * - Invalid JSON → Use defaults (logs warning) * - Invalid rate values → Throws error (business logic violation) * * @example * ```typescript * const loader = new ConfigLoader(); * const rates = loader.loadRates(); * * // Use rates in calculator * const calculator = new OnCallPaymentsCalculator( * rates.weekdayRate, * rates.weekendRate * ); * ``` */ loadRates(): RatesConfig; /** * Attempts to load configuration from file system. * * Searches for `.caloohpay.json` in multiple locations and returns * the first valid configuration found. * * @private * @returns {CalOohPayConfig | null} Parsed configuration or null if not found * * @remarks * Search order: * 1. `process.cwd()/.caloohpay.json` * 2. `~/. caloohpay.json` (user home directory) * * JSON parsing errors are caught and logged, returning null to trigger * fallback to default rates. */ private loadConfig; /** * Returns prioritized list of paths to search for config file. * * @private * @returns {string[]} Array of absolute file paths to check * * @remarks * Priority order: * 1. Current working directory (allows per-project customization) * 2. User home directory (allows user-wide defaults) */ private getConfigSearchPaths; /** * Attempts to load and parse a single config file. * * @private * @param {string} filePath - Absolute path to config file * @returns {CalOohPayConfig | null} Parsed config or null if loading fails * * @remarks * Returns null in these cases: * - File doesn't exist * - File is not readable * - JSON parsing fails * * Errors are logged to console but don't throw, allowing graceful fallback. */ private tryLoadConfigFile; /** * Validates and extracts rates from loaded configuration. * * Ensures that the configuration contains valid rate values and returns * a normalized RatesConfig object. * * @private * @param {CalOohPayConfig} config - Loaded configuration object * @returns {RatesConfig} Validated rates configuration * * @throws {Error} If rates are missing or invalid * * @remarks * Validation checks: * - `rates` object exists * - `weekdayRate` is a positive number * - `weekendRate` is a positive number * - `currency` is a non-empty string (if provided) * * Uses centralized InputValidator for consistency. */ private validateAndExtractRates; } //# sourceMappingURL=ConfigLoader.d.ts.map