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 type FilterMode = "contains" | "startsWith" | "endsWith" | "equal";

export interface TableColumn<T> {
  name: string;
  label: string;
  value: (row: T) => TableColumnValue<T>;

  type?: string;

  hidden?: boolean;
  sortable?: boolean;
  filterable?: boolean;
  filterMode?: FilterMode;
  filterFactory?: (key: string, mode: FilterMode, value: T) => Filter;
  sort?: (a: T, b: T) => number;
  filter?: (row: T, filter: string) => boolean;
  width?: string;
  class?: string;
}

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[];
}
