import { ROUTES } from "@/router/routes";

export const TIP_COFFEE_TYPE_PARAM = "coffee_type";
export const DEFAULT_TIP_COFFEE_TYPE = "small";

export type TipCoffeeType = "small" | "medium" | "large";

export interface TipCoffeeOption {
  type: TipCoffeeType;
  amountCents: number;
  fallbackName: string;
  planId: string;
}

const TIP_COFFEE_OPTIONS: Record<TipCoffeeType, TipCoffeeOption> = {
  small: {
    type: "small",
    amountCents: 499,
    fallbackName: "Small Coffee",
    planId: "tip_coffee_usd_4_99",
  },
  medium: {
    type: "medium",
    amountCents: 999,
    fallbackName: "Medium Coffee",
    planId: "tip_coffee_usd_9_99",
  },
  large: {
    type: "large",
    amountCents: 1999,
    fallbackName: "Large Coffee",
    planId: "tip_coffee_usd_19_99",
  },
};

export function resolveTipCoffeeType(
  value: string | null | undefined,
): TipCoffeeType | null {
  const normalized = value?.trim().toLowerCase();
  if (
    normalized === "small" ||
    normalized === "medium" ||
    normalized === "large"
  ) {
    return normalized;
  }
  return null;
}

export function getTipCoffeeOption(type: TipCoffeeType): TipCoffeeOption {
  return TIP_COFFEE_OPTIONS[type];
}

export function buildTipCoffeePath(type: TipCoffeeType): string {
  const params = new URLSearchParams({ [TIP_COFFEE_TYPE_PARAM]: type });
  return `${ROUTES.tip}?${params.toString()}`;
}
