export function isRecord(value) {
    return typeof value === "object" && value !== null && !Array.isArray(value);
}
export function parseOptionalBaseUrl(raw) {
    return typeof raw === "string" && raw.trim().length > 0 ? raw.trim() : undefined;
}
export function parseOptionalBoolean(raw, path, label) {
    if (typeof raw === "undefined")
        return undefined;
    if (typeof raw === "boolean")
        return raw;
    throw new Error(`Invalid config file ${path}: "${label}" must be a boolean.`);
}
export function parseOptionalNonEmptyString(raw, path, label) {
    if (typeof raw === "undefined")
        return undefined;
    if (typeof raw === "string" && raw.trim().length > 0)
        return raw.trim();
    throw new Error(`Invalid config file ${path}: "${label}" must be a string.`);
}
export function parseOptionalNumber(raw, path, label, options = {}) {
    if (typeof raw === "undefined")
        return undefined;
    if (typeof raw === "number" && Number.isFinite(raw) && (options.validate?.(raw) ?? true)) {
        return raw;
    }
    throw new Error(`Invalid config file ${path}: "${label}" must be ${options.expectation ?? "a number"}.`);
}
export function parseCliProvider(value, path) {
    const trimmed = typeof value === "string" ? value.trim().toLowerCase() : "";
    if (trimmed === "claude" ||
        trimmed === "codex" ||
        trimmed === "gemini" ||
        trimmed === "agent" ||
        trimmed === "openclaw" ||
        trimmed === "opencode" ||
        trimmed === "copilot" ||
        trimmed === "agy" ||
        trimmed === "pi") {
        return trimmed;
    }
    throw new Error(`Invalid config file ${path}: unknown CLI provider "${String(value)}".`);
}
export function parseStringArray(raw, path, label) {
    if (!Array.isArray(raw)) {
        throw new Error(`Invalid config file ${path}: "${label}" must be an array of strings.`);
    }
    const items = [];
    for (const entry of raw) {
        if (typeof entry !== "string") {
            throw new Error(`Invalid config file ${path}: "${label}" must be an array of strings.`);
        }
        const trimmed = entry.trim();
        if (!trimmed)
            continue;
        items.push(trimmed);
    }
    return items;
}
export function parseLoggingLevel(raw, path) {
    if (typeof raw !== "string") {
        throw new Error(`Invalid config file ${path}: "logging.level" must be a string.`);
    }
    const trimmed = raw.trim().toLowerCase();
    if (trimmed === "debug" || trimmed === "info" || trimmed === "warn" || trimmed === "error") {
        return trimmed;
    }
    throw new Error(`Invalid config file ${path}: "logging.level" must be one of "debug", "info", "warn", "error".`);
}
export function parseLoggingFormat(raw, path) {
    if (typeof raw !== "string") {
        throw new Error(`Invalid config file ${path}: "logging.format" must be a string.`);
    }
    const trimmed = raw.trim().toLowerCase();
    if (trimmed === "json" || trimmed === "pretty") {
        return trimmed;
    }
    throw new Error(`Invalid config file ${path}: "logging.format" must be one of "json" or "pretty".`);
}
//# sourceMappingURL=parse-helpers.js.map