import { PeriodType } from "@/types/period";

/**
 * Converts a period to total number of days
 * @param interval - Number of periods (e.g., 2 weeks = interval 2)
 * @param period - Type of period (DAY, WEEK, MONTH, YEAR)
 * @returns Total number of days
 */
export function convertPeriodToDays(
  interval: number,
  period: PeriodType
): number {
  const daysPerPeriod: Record<PeriodType, number> = {
    DAY: 1,
    WEEK: 7,
    MONTH: 30, // Average month length
    YEAR: 365,
  };

  return interval * daysPerPeriod[period];
}

/**
 * Calculates price per day based on total price and billing period
 * @param price - Total price for the period
 * @param interval - Number of periods
 * @param period - Type of period
 * @returns Price per one day
 */
export function calculatePricePerDay(
  price: number,
  interval: number,
  period: PeriodType
): number {
  const totalDays = convertPeriodToDays(interval, period);
  return price / totalDays;
}
