import { queryOptions } from '@tanstack/react-query';
import {
  getMasterOptionById,
  getMasterOptionCategories,
  getMasterOptions
} from './service';
import type { MasterOptionsFilters } from './types';

export const masterOptionKeys = {
  all: ['foundation', 'ms-options'] as const,
  lists: () => [...masterOptionKeys.all, 'list'] as const,
  list: (filters: MasterOptionsFilters) => [...masterOptionKeys.lists(), filters] as const,
  details: () => [...masterOptionKeys.all, 'detail'] as const,
  detail: (id: string) => [...masterOptionKeys.details(), id] as const,
  categories: () => [...masterOptionKeys.all, 'categories'] as const
};

export const masterOptionsQueryOptions = (filters: MasterOptionsFilters) =>
  queryOptions({
    queryKey: masterOptionKeys.list(filters),
    queryFn: () => getMasterOptions(filters)
  });

export const masterOptionByIdQueryOptions = (id: string) =>
  queryOptions({
    queryKey: masterOptionKeys.detail(id),
    queryFn: () => getMasterOptionById(id)
  });

export const masterOptionCategoriesQueryOptions = () =>
  queryOptions({
    queryKey: masterOptionKeys.categories(),
    queryFn: () => getMasterOptionCategories()
  });
