import type { DealType } from '@/lib/deal-types';

export interface BuildDealsPathOpts {
  locale?: 'he' | 'en';
  type?: DealType;
  catSlug?: string;
  tagSlugs?: string[];
  page?: number;
}

export function buildDealsPath(opts: BuildDealsPathOpts): string {
  const locale = opts.locale ?? 'he';
  const prefix = locale === 'en' ? '/en/deals' : '/deals';
  const parts: string[] = [];

  if (opts.type === 'COUPON') parts.push('coupon');
  else if (opts.type === 'GROUP') parts.push('group');
  else if (opts.type === 'ITEM') parts.push('item');

  const tags = [...(opts.tagSlugs ?? [])].sort();

  if (opts.catSlug) {
    parts.push(opts.catSlug);
  } else if (tags.length > 0) {
    parts.push('-');
  }

  if (tags.length > 0) parts.push(tags.join(','));

  if (opts.page && opts.page > 1) parts.push(`page-${opts.page}`);

  return parts.length === 0 ? prefix : `${prefix}/${parts.join('/')}`;
}
