import { unitConversion } from "@workspace/ui/utils/unit-conversions";

export const promoRuleTypes: API.PromoRuleType[] = [
  "inactive_user",
  "new_user",
  "campaign",
];

export function formatCurrency(value?: number) {
  if (typeof value !== "number") return "--";
  return `$${unitConversion("centsToDollars", value)}`;
}

export function parseOptionalNumber(value?: string) {
  if (!value) return;
  const parsed = Number(value);
  return Number.isFinite(parsed) ? parsed : undefined;
}

export function getSubscribeUnitPrice(subscribe?: API.SubscribeItem) {
  return typeof subscribe?.unit_price === "number" ? subscribe.unit_price : 0;
}
