/**
 * Known owner-team slugs and soft-normalization helper.
 *
 * `RunOwner.team` is free-form by design (external teams name themselves
 * and internal names drift). This module provides two things to keep UX
 * polished without blocking new entrants:
 *
 *   - `KNOWN_OWNER_TEAMS` — a seed list of canonical slugs that populates
 *     Studio filter comboboxes as suggestions. Not a closed enum.
 *   - `normalizeOwnerTeam()` — maps a handful of common aliases to
 *     canonical slugs. Warn-only: returns the original string when no
 *     mapping applies. Adding an alias here is a one-liner.
 *
 * @see docs/decisions/D0037-run-classification-and-ownership-taxonomy.md
 */
export const KNOWN_OWNER_TEAMS = [
    "ai-growth",
    "billing-and-integrations",
    "content-agent",
    "content-lake",
    "data",
    "design-and-research",
    "docs",
    "editorial-experience",
    "engineering",
    "identity",
    "media-library",
    "product",
    "runtime",
    "sdk",
    "ssi",
    "studio",
];
/**
 * Lowercase alias → canonical slug. Lightweight — only entries where
 * drift has been observed belong here. Unknown values pass through.
 */
const OWNER_TEAM_ALIASES = {
    "core-docs": "docs",
    coredocs: "docs",
    documentation: "docs",
    growth: "ai-growth",
    media: "media-library",
    studio_team: "studio",
    "studio-team": "studio",
};
/**
 * Normalize a free-form team slug to its canonical form.
 *
 * - Trims and lowercases.
 * - Maps known aliases to canonical slugs.
 * - Passes unknown values through unchanged (warn-only at the UI layer).
 * - Returns `"unknown"` for empty input.
 */
export function normalizeOwnerTeam(value) {
    if (!value)
        return "unknown";
    const trimmed = value.trim().toLowerCase();
    if (!trimmed)
        return "unknown";
    return OWNER_TEAM_ALIASES[trimmed] ?? trimmed;
}
export function isKnownOwnerTeam(value) {
    return KNOWN_OWNER_TEAMS.includes(value);
}
export function resolveTeamRef(value, teams) {
    const normalized = normalizeOwnerTeam(value ?? undefined);
    if (!normalized || normalized === "unknown")
        return null;
    const match = teams.find((t) => t.slug?.current === normalized);
    return match ? { _ref: match._id } : null;
}
