/**
 * @internal
 * duration.mjs — parse human-friendly duration strings into milliseconds (C56 A4).
 *
 * Accepted format: `<N><unit>` where `N` is a non-negative integer and
 * `unit ∈ {s, h, d, w, m, y}` for seconds, hours, days, weeks, months, years.
 *
 * Month and year use canonical approximations (30d and 365d respectively) —
 * they are *retention* thresholds, not clock arithmetic, so fixed-step values
 * are safer than locale-dependent calendar math.
 *
 * Examples:
 *   parseDuration('30d')  → 2_592_000_000
 *   parseDuration('2w')   → 1_209_600_000
 *   parseDuration('6m')   → 15_552_000_000
 *   parseDuration('0d')   → 0
 *   parseDuration('1h')   → 3_600_000
 *   parseDuration('30')   → throws (missing unit)
 *   parseDuration('30x')  → throws (unknown unit)
 *   parseDuration('')     → throws (empty)
 */
/**
 * @param {string} str
 * @returns {number} milliseconds (integer, >= 0)
 * @throws {Error} with `code: 'invalid-duration'` on malformed input
 * @internal
 */
export function parseDuration(str) {
    if (typeof str !== 'string') {
        const err = new Error(`parseDuration: expected string, got ${typeof str}`);
        err.code = 'invalid-duration';
        throw err;
    }
    const trimmed = str.trim();
    if (trimmed.length === 0) {
        const err = new Error('parseDuration: empty string');
        err.code = 'invalid-duration';
        throw err;
    }
    const match = /^(\d+)([shdwmy])$/i.exec(trimmed);
    if (!match) {
        const err = new Error(`parseDuration: invalid duration "${str}" (expected "<N><unit>" where unit ∈ s/h/d/w/m/y)`);
        err.code = 'invalid-duration';
        throw err;
    }
    const n = Number.parseInt(match[1], 10);
    if (!Number.isFinite(n) || n < 0) {
        const err = new Error(`parseDuration: invalid magnitude "${match[1]}"`);
        err.code = 'invalid-duration';
        throw err;
    }
    const unit = match[2].toLowerCase();
    const ms = n * UNIT_MS[unit];
    return ms;
}
const UNIT_MS = Object.freeze({
    s: 1000,
    h: 60 * 60 * 1000,
    d: 24 * 60 * 60 * 1000,
    w: 7 * 24 * 60 * 60 * 1000,
    m: 30 * 24 * 60 * 60 * 1000,
    y: 365 * 24 * 60 * 60 * 1000,
});
//# sourceMappingURL=duration.mjs.map