import { PermissionsEnum } from 'src/app/model/auth/permissionsEnum';
import { Filter } from 'src/app/model/graphql/filter/filter.model';

export type TableColumnValue<T> = T | T[keyof T] | string;

export interface TableColumn<T> {
  name: string; // internal name
  translationKey: string; // translation key
  value: (row: T) => TableColumnValue<T>;

  type?: string;

  visible?: boolean; // toggle column visibility
  hidden?: boolean; // dont even render column
  sortable?: boolean;
  filterable?: boolean;
  filterMode?: 'contains' | 'startsWith' | 'endsWith' | 'equals';
  sort?: (a: T, b: T) => number;
  filterSelector?: (mode: string, value: unknown) => Filter;
  minWidth?: string;
  width?: string;
  maxWidth?: string;
  class?: string;
}

export interface TableColumnFuzzyFilter {
  columns: string[];
  threshold?: number;
}

export interface ResolvedTableColumn<T> {
  value: TableColumnValue<T>;
  data: T;
  column: TableColumn<T>;
}

export interface TableRequireAnyPermissions {
  read?: PermissionsEnum[];
  create?: PermissionsEnum[];
  update?: PermissionsEnum[];
  delete?: PermissionsEnum[];
  restore?: PermissionsEnum[];
}
