import { queryOptions } from '@tanstack/react-query';
import {
  getDocumentSequenceById,
  getDocumentSequences,
  previewDocumentSequence
} from './client-service';

export const documentSequenceKeys = {
  all: ['crm-document-sequences'] as const,
  lists: () => [...documentSequenceKeys.all, 'list'] as const,
  list: () => [...documentSequenceKeys.lists(), 'all'] as const,
  details: () => [...documentSequenceKeys.all, 'detail'] as const,
  detail: (id: string) => [...documentSequenceKeys.details(), id] as const,
  previewRoot: () => [...documentSequenceKeys.all, 'preview'] as const,
  preview: (id: string) => [...documentSequenceKeys.previewRoot(), id] as const
};

export const documentSequencesQueryOptions = () =>
  queryOptions({
    queryKey: documentSequenceKeys.list(),
    queryFn: () => getDocumentSequences()
  });

export const documentSequenceByIdOptions = (id: string) =>
  queryOptions({
    queryKey: documentSequenceKeys.detail(id),
    queryFn: () => getDocumentSequenceById(id)
  });

export const documentSequencePreviewOptions = (id: string) =>
  queryOptions({
    queryKey: documentSequenceKeys.preview(id),
    queryFn: () => previewDocumentSequence(id)
  });
