import { SemanticType } from '../Semantics.js';
/**
 * Type guard to check if a semantic is a Currency semantic.
 */
export const isCurrencySemantic = (semantic) => {
    return semantic.id === SemanticType.Currency;
};
/**
 * Helper function to create a Currency semantic with configuration.
 */
export const createCurrencySemantic = (config = {}) => {
    const mergedConfig = {
        ...DEFAULT_CURRENCY_CONFIG,
        ...config,
    };
    // Merge metadata separately
    if (config.metadata) {
        mergedConfig.metadata = { ...config.metadata };
    }
    return {
        id: SemanticType.Currency,
        config: mergedConfig,
    };
};
/**
 * Default configuration for Currency semantic.
 * Optimized for common e-commerce use cases with USD currency.
 */
export const DEFAULT_CURRENCY_CONFIG = {
    storageFormat: 'decimal',
    defaultCurrency: 'USD',
    decimalPlaces: 2,
    allowNegative: false,
    validateCurrencyCode: true,
};
/**
 * Predefined configurations for common use cases.
 */
export const CURRENCY_PRESETS = {
    /**
     * Simple USD decimal storage - good for most e-commerce sites.
     */
    USD_DECIMAL: createCurrencySemantic({
        storageFormat: 'decimal',
        defaultCurrency: 'USD',
        decimalPlaces: 2,
        allowNegative: false,
    }),
    /**
     * Integer cents storage - avoids floating point issues, good for financial calculations.
     */
    USD_CENTS: createCurrencySemantic({
        storageFormat: 'integer_cents',
        defaultCurrency: 'USD',
        decimalPlaces: 2,
        allowNegative: false,
    }),
    /**
     * Multi-currency support with complex object storage.
     */
    MULTI_CURRENCY: createCurrencySemantic({
        storageFormat: 'complex_object',
        allowedCurrencies: ['USD', 'EUR', 'GBP', 'JPY', 'CAD'],
        decimalPlaces: 2,
        allowNegative: false,
    }),
    /**
     * Configuration that allows negative values for refunds, discounts, etc.
     */
    WITH_NEGATIVES: createCurrencySemantic({
        storageFormat: 'decimal',
        defaultCurrency: 'USD',
        decimalPlaces: 2,
        allowNegative: true,
    }),
    /**
     * High-precision configuration for cryptocurrency or precious metals.
     */
    HIGH_PRECISION: createCurrencySemantic({
        storageFormat: 'decimal',
        defaultCurrency: 'BTC',
        decimalPlaces: 8,
        allowNegative: false,
    }),
};
/**
 * Helper function to validate a currency configuration.
 */
export const validateCurrencyConfig = (config) => {
    const errors = [];
    if (config.storageFormat !== 'complex_object' && !config.defaultCurrency) {
        errors.push('defaultCurrency is required when storageFormat is not complex_object');
    }
    if (config.decimalPlaces !== undefined && config.decimalPlaces < 0) {
        errors.push('decimalPlaces must be non-negative');
    }
    return errors;
};
//# sourceMappingURL=Currency.js.map