import { Category } from '../../../../core/categories/models/category-domain.model';
import { CatalogLayoutMode } from '../../../../core/products/models/catalog-experience.model';

export type CatalogSort = 'relevance' | 'price_asc' | 'price_desc' | 'popular' | 'rating' | 'latest' | 'discount';

export interface CatalogPriceRange {
  min?: number;
  max?: number;
}

export interface CatalogPaginationState {
  page: number;
  count: number;
  skip: number;
  total: number;
  hasMore: boolean;
}

export interface CatalogFilterState {
  categoryIds: number[];
  priceRange: CatalogPriceRange;
  attributes: Record<string, string[]>;
  values: Record<string, string[]>;
  ranges: Record<string, CatalogPriceRange>;
  toggles: Record<string, boolean>;
}

export interface CatalogState {
  category: Category | null;
  search: string;
  sort: CatalogSort;
  layout: CatalogLayoutMode;
  priceRange: CatalogPriceRange;
  attributes: Record<string, string[]>;
  pagination: CatalogPaginationState;
  filters: CatalogFilterState;
}

export const DEFAULT_CATALOG_PAGE_SIZE = 24;

export function createInitialCatalogState(): CatalogState {
  return {
    category: null,
    search: '',
    sort: 'relevance',
    priceRange: {},
    attributes: {},
    layout: 'grid',
    pagination: {
      page: 1,
      count: DEFAULT_CATALOG_PAGE_SIZE,
      skip: 0,
      total: 0,
      hasMore: true,
    },
    filters: {
      categoryIds: [],
      priceRange: {},
      attributes: {},
      values: {},
      ranges: {},
      toggles: {},
    },
  };
}
