import { QueryObserverResult, RefetchOptions } from '@tanstack/react-query';

import { Duration } from '../TokenCreation/models';

export enum SortOrder {
  asc = 'asc',
  desc = 'desc'
}

export interface DataListing {
  isError: boolean;
  isLoading: boolean;
  limit?: number;
  page?: number;
  rows?: Array<Token>;
  total?: number;
}
export interface UseTokenListing {
  changeLimit: (value: number) => void;
  changePage: (value: number) => void;
  dataListing: DataListing;
  isRefetching: boolean;
  onSort: (sortParams: SortParams) => void;
  refetch: (
    options?: RefetchOptions | undefined
  ) => Promise<QueryObserverResult<unknown, Error>>;
  sortOrder: SortOrder;
}

export interface PersonalInformation {
  id: number;
  name: string;
}

export interface Token {
  creationDate: string;
  creator: PersonalInformation;
  expirationDate: string;
  isRevoked: boolean;
  name: string;
  user: PersonalInformation;
}
export interface Row {
  row: Token;
}

export interface SortParams {
  sortField: string;
  sortOrder: string;
}

export interface CreateTokenFormValues {
  customizeDate: null | Date;
  duration: Omit<Duration, 'unit'> | null;
  tokenName: string;
  user: PersonalInformation | null;
}

interface User {
  alias: string;
  id: number;
}

export interface NamedEntity {
  id: number;
  name: string;
}

export interface Filter {
  creationDate: Date | null;
  creators: Array<NamedEntity>;
  disabled: boolean;
  enabled: boolean;
  expirationDate: Date | null;
  name: string;
  types: Array<NamedEntity>;
  users: Array<User>;
}
