import { InjectionToken, Provider } from '@angular/core';
import { ProductRouterLinkBuilder } from './product-router-link.types';

/**
 * Injection token for the product router link builder function.
 * Provides a default implementation that builds a URL in the format:
 * `/kunde/{timestamp}/product/details/{ean}/ean`
 */
export const PRODUCT_ROUTER_LINK_BUILDER =
  new InjectionToken<ProductRouterLinkBuilder>('PRODUCT_ROUTER_LINK_BUILDER', {
    factory: () => (ean: string) =>
      `/kunde/${Date.now()}/product/details/${ean}/ean`,
  });

/**
 * Provides a custom implementation of the product router link builder.
 * @param builder Custom function to build product URLs from EANs
 * @returns Provider array to be included in the application's providers
 */
export function provideProductRouterLinkBuilder(
  builder: ProductRouterLinkBuilder,
): Provider[] {
  return [
    {
      provide: PRODUCT_ROUTER_LINK_BUILDER,
      useValue: builder,
    },
  ];
}
