import { CatalogLayoutMode } from '../../../core/products/models/catalog-experience.model';
import { ProductSort } from '../../../core/products/models/product-domain.model';
import { SearchFilterState, SearchResult, SearchSuggestion } from './search.model';

export interface SearchState {
  // Canonical feature state
  currentQuery: string;
  loading: boolean;
  results: SearchResult | null;
  suggestions: SearchSuggestion[];
  recentSearches: string[];
  popularSearches: string[];
  selectedFilters: SearchFilterState;
  currentSort: ProductSort | 'discount';
  currentPage: number;
  pageSize: number;
  totalResults: number;
  layout: CatalogLayoutMode;

  // Legacy compatibility fields
  text: string;
  sort: ProductSort | 'discount';
  page: number;
  filters: SearchFilterState;
}

export function createInitialSearchState(pageSize = 24): SearchState {
  return {
    currentQuery: '',
    loading: false,
    results: null,
    suggestions: [],
    recentSearches: [],
    popularSearches: [],
    selectedFilters: {
      values: {},
      ranges: {},
      toggles: {},
    },
    currentSort: 'relevance',
    currentPage: 1,
    pageSize,
    totalResults: 0,
    layout: 'grid',
    text: '',
    sort: 'relevance',
    page: 1,
    filters: {
      values: {},
      ranges: {},
      toggles: {},
    },
  };
}
