export const parseOptionalSetting = (raw, parse, strict) => {
    if (typeof raw !== "string")
        return null;
    try {
        return parse(raw);
    }
    catch (error) {
        if (strict)
            throw error;
        return null;
    }
};
export const parseOptionalBoolean = (raw, strict, label = "--timestamps") => {
    if (typeof raw === "boolean")
        return raw;
    if (typeof raw !== "string")
        return null;
    const normalized = raw.trim().toLowerCase();
    if (!normalized)
        return null;
    if (normalized === "true" || normalized === "1" || normalized === "yes" || normalized === "on") {
        return true;
    }
    if (normalized === "false" || normalized === "0" || normalized === "no" || normalized === "off") {
        return false;
    }
    if (strict) {
        throw new Error(`Unsupported ${label}: ${raw}`);
    }
    return null;
};
export const parseCliProvider = (raw) => {
    const normalized = raw.trim().toLowerCase();
    if (normalized === "claude")
        return "claude";
    if (normalized === "gemini")
        return "gemini";
    if (normalized === "codex")
        return "codex";
    if (normalized === "agent")
        return "agent";
    if (normalized === "openclaw")
        return "openclaw";
    if (normalized === "opencode")
        return "opencode";
    if (normalized === "copilot")
        return "copilot";
    if (normalized === "agy")
        return "agy";
    if (normalized === "pi")
        return "pi";
    return null;
};
export const parseOptionalCliProviderOrder = (raw, strict) => {
    if (typeof raw === "undefined" || raw === null)
        return null;
    const items = Array.isArray(raw)
        ? raw.filter((entry) => typeof entry === "string")
        : typeof raw === "string"
            ? raw
                .split(/[,\s]+/)
                .map((entry) => entry.trim())
                .filter(Boolean)
            : [];
    if (items.length === 0) {
        if (strict)
            throw new Error(`Unsupported --auto-cli-order: ${String(raw)}`);
        return null;
    }
    const out = [];
    for (const item of items) {
        const provider = parseCliProvider(item);
        if (!provider) {
            if (strict)
                throw new Error(`Unsupported --auto-cli-order provider: ${item}`);
            return null;
        }
        if (!out.includes(provider))
            out.push(provider);
    }
    return out.length > 0 ? out : null;
};
//# sourceMappingURL=run-settings-parse.js.map