import type { YtChannelMeta } from "@/components/YtChannelMetaBadges"; import { brandHintForChannel } from "@/lib/ytBrandHints"; import type { YtProfileSnippet } from "@/components/YtChannelProfileSnippet"; export type ChannelMetaInput = { id?: string; enabled?: boolean; authorized?: boolean; oauth_ok?: number | boolean | null; oauth_error?: string; oauth_profile_id?: string; youtube_channel_id?: string; note?: string; brand_hint?: string; ypp_ok?: number | null; yt_profile?: YtProfileSnippet | null; }; export function buildChannelMeta( ch: ChannelMetaInput, oauthIssue?: { oauth_error?: string } | null, ): YtChannelMeta { const staleReauth = Boolean(ch.authorized && (ch.oauth_error || "").includes("ι‡ζŽˆζƒδΈ­")); const oauthBad = Boolean(oauthIssue) && !staleReauth; const brandHint = String(ch.brand_hint || "").trim() || brandHintForChannel(ch.yt_profile, ch.youtube_channel_id, ch.note); return { enabled: ch.enabled, authorized: ch.authorized, oauthOk: staleReauth ? 1 : oauthBad ? 0 : ch.oauth_ok, oauthError: oauthIssue?.oauth_error || ch.oauth_error, brandHint, yppOk: ch.ypp_ok, oauthProfileId: ch.oauth_profile_id, }; }