import { queryOptions } from '@tanstack/react-query';
import { getUserMasterOptions, getUsers } from './service';
import type { User, UserFilters } from './types';

export type { User };

const userAllKey = ['users'] as const;

export const userKeys = {
  all: userAllKey,
  list: (filters: UserFilters) => [...userAllKey, 'list', filters] as const,
  detail: (id: string) => [...userAllKey, 'detail', id] as const,
  options: [...userAllKey, 'options'] as const
};

export const usersQueryOptions = (filters: UserFilters) =>
  queryOptions({
    queryKey: userKeys.list(filters),
    queryFn: () => getUsers(filters)
  });

export const userMasterOptionsQueryOptions = () =>
  queryOptions({
    queryKey: userKeys.options,
    queryFn: getUserMasterOptions
  });
