import type { Package } from '../../api'; export function classifyPackageTier(price: number, activePrice: number | null): { isUpgrade: boolean; isDowngrade: boolean; } { if (activePrice === null) { return { isUpgrade: false, isDowngrade: false }; } return { isUpgrade: price > activePrice, isDowngrade: price < activePrice, }; } export function selectRecommendedPackageId( packages: Package[], feature: string | null, activePrice: number | null ): number | null { if (!feature) { return null; } const candidates = packages.filter((pkg) => pkg.features?.[feature]); if (candidates.length === 0) { return null; } const upgradeCandidates = activePrice === null ? candidates : candidates.filter((pkg) => pkg.price > activePrice); const pool = upgradeCandidates.length ? upgradeCandidates : candidates; const sorted = [...pool].sort((a, b) => a.price - b.price); return sorted[0]?.id ?? null; }