import { Product } from '@/domain/entities';
import { IProductRepository } from '@/application/ports/IProductRepository';
import { PRODUCT_CATALOG } from '@/infrastructure/data/products.data';

/**
 * INFRASTRUCTURE — In-memory product source (replace with API later)
 */
export class InMemoryProductRepository implements IProductRepository {
  constructor(private readonly catalog: Product[] = PRODUCT_CATALOG) {}

  findAll(): Product[] {
    return [...this.catalog];
  }

  findBySlug(slug: string): Product | undefined {
    return this.catalog.find((p) => p.slug === slug);
  }

  findByCategory(category: string): Product[] {
    return this.catalog.filter((p) => p.category === category);
  }

  findFeatured(): Product[] {
    return this.catalog.filter((p) => p.featured);
  }

  findById(id: string): Product | undefined {
    return this.catalog.find((p) => p.id === id);
  }
}