import { Product } from '@/domain/entities';
import { LocalizedProduct } from '@/application/dtos/LocalizedProduct';
import { LocalizeProductUseCase } from '@/application/use-cases/catalog/LocalizeProduct';
import { ITranslationService } from '@/application/ports/ITranslationService';

type Translator = (path: string, params?: Record<string, string | number>) => string;

export type { LocalizedProduct };

class TranslatorAdapter implements ITranslationService {
  constructor(private readonly t: Translator) {}

  translate(
    path: string,
    params?: Record<string, string | number>
  ): string {
    return this.t(path, params);
  }
}

export function localizeProduct(product: Product, t: Translator): LocalizedProduct {
  return new LocalizeProductUseCase(new TranslatorAdapter(t)).execute(product);
}

export function localizeCategory(
  categoryId: Product['category'],
  t: Translator
): { name: string; description: string } {
  return {
    name: t(`categories.${categoryId}.name`),
    description: t(`categories.${categoryId}.description`),
  };
}