import { Product, ProductSort } from '../../../core/products/models/product-domain.model';
import { AppIconName } from '../../../shared/ui/icon/icon-registry';

export type SearchFilterType =
  | 'checkbox'
  | 'radio'
  | 'toggle'
  | 'range'
  | 'slider'
  | 'color'
  | 'size'
  | 'rating'
  | 'availability';

export type SearchSuggestionType =
  | 'product'
  | 'category'
  | 'brand'
  | 'collection'
  | 'seller'
  | 'static-page'
  | 'ai';

export interface SearchNavigationTarget {
  route: string;
  params?: Record<string, string | number>;
  query?: Record<string, string | number | boolean>;
}

export interface SearchSuggestion {
  id: string;
  type: SearchSuggestionType;
  title: string;
  text: string;
  kind?: 'live' | 'recent' | 'popular';
  subtitle?: string;
  icon: AppIconName;
  target: SearchNavigationTarget;
  score?: number;
}

export interface SearchQuery {
  text: string;
  categoryIds: number[];
  subcategoryIds: string[];
  filters: SearchFilterState;
  sort: ProductSort | 'discount';
  page: number;
  pageSize: number;
}

export interface SearchResult<TItem = Product> {
  query: SearchQuery;
  items: TItem[];
  total: number;
  page: number;
  pageSize: number;
  summary: string;
}

export interface FilterOption {
  id: string;
  label: string;
  value: string;
  count?: number;
  colorHex?: string;
  availability?: 'in-stock' | 'low-stock' | 'out-of-stock';
  rating?: number;
}

export interface FilterGroup {
  id: string;
  label: string;
  type: SearchFilterType;
  options: FilterOption[];
  min?: number;
  max?: number;
  step?: number;
  enabled: boolean;
}

export interface SortOption {
  id: ProductSort | 'discount';
  label: string;
  enabled: boolean;
}

export interface SearchHistory {
  items: string[];
  recent: string[];
  popular: string[];
}

export interface SearchFilterState {
  values: Record<string, string[]>;
  ranges: Record<string, { min?: number; max?: number }>;
  toggles: Record<string, boolean>;
}

export interface SearchAnalyticsEvent {
  query: string;
  tenant: string;
  language: string;
  timestamp: string;
  resultCount: number;
}
