import { queryOptions } from '@tanstack/react-query';
import { getLeadById, getLeads } from './service';
import type { LeadListFilters } from './types';

export const leadKeys = {
  all: ['crm-leads'] as const,
  lists: () => [...leadKeys.all, 'list'] as const,
  list: (filters: LeadListFilters) => [...leadKeys.lists(), filters] as const,
  details: () => [...leadKeys.all, 'detail'] as const,
  detail: (id: string) => [...leadKeys.details(), id] as const
};

export const leadsQueryOptions = (filters: LeadListFilters) =>
  queryOptions({
    queryKey: leadKeys.list(filters),
    queryFn: () => getLeads(filters)
  });

export const leadByIdOptions = (id: string) =>
  queryOptions({
    queryKey: leadKeys.detail(id),
    queryFn: () => getLeadById(id)
  });
