import { Product } from '@/domain/entities';
import { LocalizedProduct } from '@/application/dtos/LocalizedProduct';
import { ITranslationService } from '@/application/ports/ITranslationService';

/**
 * USE CASE — Turn a Product entity into display-ready LocalizedProduct
 */
export class LocalizeProductUseCase {
  constructor(private readonly translation: ITranslationService) {}

  execute(product: Product): LocalizedProduct {
    const base = `products.${product.id}`;
    const t = this.translation.translate.bind(this.translation);

    return {
      ...product,
      name: t(`${base}.name`),
      description: t(`${base}.description`),
      longDescription: t(`${base}.longDescription`),
      priceUnit: t(`priceUnit.${product.priceUnitKey}`),
      badge: product.badgeKey ? t(`badges.${product.badgeKey}`) : undefined,
    };
  }

  executeMany(products: Product[]): LocalizedProduct[] {
    return products.map((p) => this.execute(p));
  }
}