import type { PlanRules } from '@repo/api-contract';

export type PlanPrice = {
  amount: number;
  currency: string;
};

export function resolvePlanPrice(
  defaultPrice: number,
  rules: PlanRules,
  countryCode?: string
): PlanPrice {
  if (!countryCode) {
    return { amount: defaultPrice, currency: 'USD' };
  }

  if (rules.version === 'v2' && rules.pricing?.overrides) {
    const override = rules.pricing.overrides[countryCode];
    if (override) {
      return { amount: override.amount, currency: override.currency };
    }
  }

  return { amount: defaultPrice, currency: 'USD' };
}
