/**
 * COMPOSITION ROOT — Wires ports to infrastructure and exposes use cases.
 * This is the only place that should know concrete implementations.
 */
import { InMemoryProductRepository } from '@/infrastructure/repositories/InMemoryProductRepository';
import {
  ZustandCartRepository,
} from '@/infrastructure/persistence/zustand/cartStore';
import {
  ZustandAuthRepository,
} from '@/infrastructure/persistence/zustand/authStore';
import {
  ZustandWishlistRepository,
} from '@/infrastructure/persistence/zustand/wishlistStore';
import { I18nTranslationService } from '@/infrastructure/i18n/I18nTranslationService';
import { LocalizeProductUseCase } from '@/application/use-cases/catalog/LocalizeProduct';
import { FilterProductsUseCase } from '@/application/use-cases/catalog/FilterProducts';
import { GetProductBySlugUseCase } from '@/application/use-cases/catalog/GetProductBySlug';
import { AddToCartUseCase } from '@/application/use-cases/cart/AddToCart';
import { GetCartSummaryUseCase } from '@/application/use-cases/cart/GetCartSummary';
import { UpdateCartQuantityUseCase } from '@/application/use-cases/cart/UpdateCartQuantity';
import { RemoveFromCartUseCase } from '@/application/use-cases/cart/RemoveFromCart';
import { PlaceOrderUseCase } from '@/application/use-cases/checkout/PlaceOrder';
import { LoginUseCase } from '@/application/use-cases/auth/Login';
import { RegisterUseCase } from '@/application/use-cases/auth/Register';
import { ToggleWishlistUseCase } from '@/application/use-cases/wishlist/ToggleWishlist';
import { Locale } from '@/i18n/types';

class ApplicationContainer {
  readonly productRepository = new InMemoryProductRepository();
  readonly cartRepository = new ZustandCartRepository();
  readonly authRepository = new ZustandAuthRepository();
  readonly wishlistRepository = new ZustandWishlistRepository();

  createTranslationService(locale: Locale): I18nTranslationService {
    return new I18nTranslationService(locale);
  }

  createLocalizeProduct(locale: Locale): LocalizeProductUseCase {
    return new LocalizeProductUseCase(this.createTranslationService(locale));
  }

  readonly getProductBySlug = new GetProductBySlugUseCase(this.productRepository);
  readonly addToCart = new AddToCartUseCase(this.cartRepository);
  readonly getCartSummary = new GetCartSummaryUseCase(this.cartRepository);
  readonly updateCartQuantity = new UpdateCartQuantityUseCase(this.cartRepository);
  readonly removeFromCart = new RemoveFromCartUseCase(this.cartRepository);
  readonly placeOrder = new PlaceOrderUseCase(
    this.cartRepository,
    this.authRepository
  );
  readonly login = new LoginUseCase(this.authRepository);
  readonly register = new RegisterUseCase(this.authRepository);
  readonly toggleWishlist = new ToggleWishlistUseCase(this.wishlistRepository);

  createFilterProducts(locale: Locale): FilterProductsUseCase {
    return new FilterProductsUseCase(
      this.productRepository,
      this.createLocalizeProduct(locale)
    );
  }
}

export const container = new ApplicationContainer();