/**
 * Helpers for working with ValidationRuleResult. Since v4, `result.issues` is
 * always a present array — consumers iterate it directly without a normalizer.
 */
/**
 * Build a deterministic id from arbitrary parts. Same input → same id across
 * re-runs, so persisted client responses re-attach when validation re-runs.
 *
 * Falls back to the fallback id if the slug is empty.
 */
export function make_issue_id(parts, fallback) {
    const slug = parts
        .filter(p => p !== null && p !== undefined && String(p).trim() !== '')
        .map(p => String(p).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, ''))
        .filter(Boolean)
        .join('--');
    return slug || fallback;
}
/** Canonical clarification id for an issue. Stable across re-runs when issue_id is deterministic. */
export function make_clarification_id(content_id, rule_id, issue_id) {
    return `clr_${content_id}_${rule_id}_${issue_id}`;
}
/**
 * Coerce a possibly-legacy ValidationRuleResult into the v4 shape. Persisted
 * form data from before v4.0.0 may still have `{ has_issue, issue_description }`
 * without an `issues` array — this helper safely upgrades it on read.
 *
 * Cheap: if the input already has `issues`, returns the input unchanged.
 */
export function normalize_validation_rule_result(result) {
    if (Array.isArray(result.issues)) {
        return result;
    }
    const legacy = result;
    const issues = legacy.has_issue
        ? [{
                issue_id: '0',
                issue_description: legacy.issue_description ?? 'A validation issue was detected.',
                ...(legacy.confidence !== undefined ? { confidence: legacy.confidence } : {}),
            }]
        : [];
    const summary = !legacy.has_issue ? legacy.issue_description : undefined;
    return {
        ...result,
        issues,
        ...(summary ? { summary } : {}),
    };
}
/** Coerce a list of possibly-legacy results. */
export function normalize_validation_rule_results(results) {
    if (!results)
        return [];
    return results.map(normalize_validation_rule_result);
}
//# sourceMappingURL=validation_result.js.map