import { MealCategory } from '@/src/types/recipe';
import type { TFunction } from 'i18next';

export function categoryLabel(category: MealCategory, t: TFunction): string {
  switch (category) {
    case MealCategory.Breakfast:
      return t('categories.breakfast');
    case MealCategory.SecondBreakfast:
      return t('categories.secondBreakfast');
    case MealCategory.Lunch:
      return t('categories.lunch');
    case MealCategory.Dinner:
      return t('categories.dinner');
    default:
      return t('categories.unknown');
  }
}

export const ALL_CATEGORIES = [
  MealCategory.Breakfast,
  MealCategory.SecondBreakfast,
  MealCategory.Lunch,
  MealCategory.Dinner,
];

export function parseCategoryParam(value: string): MealCategory | null {
  const num = Number(value);
  if (Number.isInteger(num) && num >= 0 && num <= 3) {
    return num as MealCategory;
  }
  return null;
}

export function parseOptionalNumber(value: string): number | null {
  const trimmed = value.trim();
  if (!trimmed) return null;
  const num = Number(trimmed);
  return Number.isFinite(num) ? num : null;
}
