/**
 * Common types used across ui-data-utils
 */

/**
 * Sort direction
 */
export type SortDirection = 'asc' | 'desc';

/**
 * Supported data types for comparison
 */
export type DataType = 'string' | 'number' | 'date' | 'boolean';

/**
 * Sort configuration for single property
 */
export interface SortConfig<T = any> {
  /** Property key to sort by */
  key: keyof T;
  /** Sort direction */
  direction: SortDirection;
  /** Data type for proper comparison */
  dataType?: DataType;
}

/**
 * Multi-column sort configuration
 */
export interface MultiSortConfig<T = any> {
  /** Array of sort configurations in priority order */
  sorts: SortConfig<T>[];
}

/**
 * Comparator function type
 */
export type ComparatorFn<T = any> = (a: T, b: T) => number;

/**
 * Filter operator types
 */
export type FilterOperator = 
  | 'equals' 
  | 'not_equals'
  | 'contains' 
  | 'not_contains'
  | 'starts_with' 
  | 'ends_with'
  | 'greater_than' 
  | 'greater_than_equal'
  | 'less_than' 
  | 'less_than_equal'
  | 'between'
  | 'in'
  | 'not_in'
  | 'is_empty'
  | 'is_not_empty';

/**
 * Filter configuration
 */
export interface FilterConfig<T = any> {
  /** Property key to filter by */
  key: keyof T;
  /** Filter operator */
  operator: FilterOperator;
  /** Filter value(s) */
  value: any;
  /** Data type for proper comparison */
  dataType?: DataType;
}

/**
 * Pagination configuration
 */
export interface PaginationConfig {
  /** Current page (1-based) */
  page: number;
  /** Items per page */
  pageSize: number;
}

/**
 * Pagination result
 */
export interface PaginationResult<T = any> {
  /** Paginated data */
  data: T[];
  /** Current page */
  page: number;
  /** Items per page */
  pageSize: number;
  /** Total number of items */
  totalItems: number;
  /** Total number of pages */
  totalPages: number;
  /** Has previous page */
  hasPrevious: boolean;
  /** Has next page */
  hasNext: boolean;
  /** Start index (0-based) */
  startIndex: number;
  /** End index (0-based) */
  endIndex: number;
}

/**
 * Aggregation functions
 */
export type AggregationFunction = 'sum' | 'avg' | 'min' | 'max' | 'count';

/**
 * Aggregation result
 */
export interface AggregationResult {
  [key: string]: number;
}

/**
 * Group by result
 */
export interface GroupByResult<T = any> {
  /** Group key */
  key: any;
  /** Items in this group */
  items: T[];
  /** Group count */
  count: number;
}