/* ────────────────────────────────────────────────────────────────
   Validation — Boundary validation utilities for public APIs
──────────────────────────────────────────────────────────────── */
/* ── Range validation ─────────────────────────────────────────── */
function clamp(value, min, max) {
    return Math.max(min, Math.min(max, value));
}
function clampPositive(value) {
    return Math.max(0, value);
}
function assertFinite(value, name) {
    if (!Number.isFinite(value)) {
        throw new RangeError(`[Validation] ${name} must be a finite number, got ${value}`);
    }
}
function assertPositive(value, name) {
    if (!Number.isFinite(value) || value <= 0) {
        throw new RangeError(`[Validation] ${name} must be a positive number, got ${value}`);
    }
}
function assertNonNegative(value, name) {
    if (!Number.isFinite(value) || value < 0) {
        throw new RangeError(`[Validation] ${name} must be a non-negative number, got ${value}`);
    }
}
function assertInRange(value, min, max, name) {
    if (!Number.isFinite(value) || value < min || value > max) {
        throw new RangeError(`[Validation] ${name} must be between ${min} and ${max}, got ${value}`);
    }
}
/* ── String validation ────────────────────────────────────────── */
function assertNonEmpty(value, name) {
    if (!value || value.trim().length === 0) {
        throw new TypeError(`[Validation] ${name} must be a non-empty string`);
    }
}
/* ── Canvas validation ────────────────────────────────────────── */
function assertCanvasElement(el, name = 'canvas') {
    if (!el || typeof el.getContext !== 'function') {
        throw new TypeError(`[Validation] ${name} must be a valid HTMLCanvasElement`);
    }
}
function validateGameSettings(settings) {
    const result = { valid: true, warnings: [], errors: [] };
    if (settings.width !== undefined) {
        if (settings.width < 64 || settings.width > 7680) {
            result.errors.push(`width ${settings.width} out of range [64, 7680]`);
            result.valid = false;
        }
        else if (settings.width < 320) {
            result.warnings.push(`width ${settings.width} is very small, consider 320+`);
        }
    }
    if (settings.height !== undefined) {
        if (settings.height < 64 || settings.height > 4320) {
            result.errors.push(`height ${settings.height} out of range [64, 4320]`);
            result.valid = false;
        }
        else if (settings.height < 240) {
            result.warnings.push(`height ${settings.height} is very small, consider 240+`);
        }
    }
    if (settings.targetFps !== undefined) {
        if (settings.targetFps < 1 || settings.targetFps > 300) {
            result.errors.push(`targetFps ${settings.targetFps} out of range [1, 300]`);
            result.valid = false;
        }
        else if (settings.targetFps > 120) {
            result.warnings.push(`targetFps ${settings.targetFps} is high, most displays are 60-120 Hz`);
        }
    }
    if (settings.maxPlayers !== undefined) {
        if (settings.maxPlayers < 1 || settings.maxPlayers > 12) {
            result.errors.push(`maxPlayers ${settings.maxPlayers} out of range [1, 12]`);
            result.valid = false;
        }
    }
    return result;
}
/* ── Physics validation ───────────────────────────────────────── */
function validatePhysicsSettings(settings) {
    const result = { valid: true, warnings: [], errors: [] };
    if (settings.fixedTimestep !== undefined) {
        if (settings.fixedTimestep < 0.001 || settings.fixedTimestep > 0.1) {
            result.errors.push(`fixedTimestep ${settings.fixedTimestep} out of range [0.001, 0.1]`);
            result.valid = false;
        }
        else if (settings.fixedTimestep > 1 / 30) {
            result.warnings.push(`fixedTimestep ${settings.fixedTimestep}s is large, physics accuracy may suffer`);
        }
    }
    if (settings.velocityIterations !== undefined) {
        if (settings.velocityIterations < 1 || settings.velocityIterations > 100) {
            result.errors.push(`velocityIterations ${settings.velocityIterations} out of range [1, 100]`);
            result.valid = false;
        }
    }
    if (settings.positionIterations !== undefined) {
        if (settings.positionIterations < 1 || settings.positionIterations > 100) {
            result.errors.push(`positionIterations ${settings.positionIterations} out of range [1, 100]`);
            result.valid = false;
        }
    }
    return result;
}

export { assertCanvasElement, assertFinite, assertInRange, assertNonEmpty, assertNonNegative, assertPositive, clamp, clampPositive, validateGameSettings, validatePhysicsSettings };
//# sourceMappingURL=Validation.js.map
