function cleanLabel(value) {
    const label = value?.trim();
    return label ? label : null;
}
function sameLabel(left, right) {
    return left.localeCompare(right, undefined, { sensitivity: "accent" }) === 0;
}
/**
 * Describe what a browser run will try to select without presenting the target as observed fact.
 */
export function formatBrowserModelTarget({ model, desiredModel, modelStrategy, }) {
    const requested = cleanLabel(model) ?? "n/a";
    if (modelStrategy === "current" || modelStrategy === "ignore") {
        return `picker=${modelStrategy}; requested=${requested}`;
    }
    const target = cleanLabel(desiredModel);
    if (!target) {
        return requested;
    }
    return `target=${target}; requested=${requested}`;
}
/**
 * Prefer picker evidence only when Oracle verified it. Otherwise retain the requested CLI key.
 * In particular, a bare `Pro` picker label must not be expanded to a server-side model version.
 */
export function resolveBrowserModelDisplayName({ model, evidence, }) {
    const verifiedLabel = evidence?.verified ? cleanLabel(evidence.resolvedLabel) : null;
    return verifiedLabel ?? cleanLabel(model) ?? "n/a";
}
export function formatBrowserModelWithRequestedKey(input) {
    const displayName = resolveBrowserModelDisplayName(input);
    const requested = cleanLabel(input.model);
    if (!requested || sameLabel(displayName, requested)) {
        return displayName;
    }
    return `${displayName} (requested ${requested})`;
}
export function resolveSessionBrowserModelDisplayName(metadata, model = metadata.model) {
    const sessionModel = cleanLabel(metadata.model);
    const requestedModel = cleanLabel(model);
    const evidenceApplies = requestedModel === null
        ? sessionModel === null
        : sessionModel !== null && sameLabel(requestedModel, sessionModel);
    return resolveBrowserModelDisplayName({
        model,
        evidence: evidenceApplies ? metadata.browser?.modelSelection : undefined,
    });
}
export function formatSessionBrowserModelWithRequestedKey(metadata, model = metadata.model) {
    const sessionModel = cleanLabel(metadata.model);
    const requestedModel = cleanLabel(model);
    const evidenceApplies = requestedModel === null
        ? sessionModel === null
        : sessionModel !== null && sameLabel(requestedModel, sessionModel);
    return formatBrowserModelWithRequestedKey({
        model,
        evidence: evidenceApplies ? metadata.browser?.modelSelection : undefined,
    });
}
export function formatBrowserModelSelectionEvidence(evidence, model) {
    const requestedKey = cleanLabel(model) ?? "(none)";
    const target = cleanLabel(evidence.requestedModel) ?? "(none)";
    const resolvedLabel = cleanLabel(evidence.resolvedLabel) ?? "(unavailable)";
    const strategy = evidence.strategy ?? "(default)";
    const verified = evidence.verified ? "yes" : "no";
    return `requestedKey=${requestedKey}; target=${target}; resolvedLabel=${resolvedLabel}; status=${evidence.status}; strategy=${strategy}; verified=${verified}; source=${evidence.source}; capturedAt=${evidence.capturedAt}`;
}
