import { queryOptions } from '@tanstack/react-query';
import {
  getTrainingPolicies,
  getTrainingPolicy,
  getTrainingPolicyHistory
} from './service';
import type { TrainingPolicyFilters } from './types';

export const trainingPolicyKeys = {
  all: ['training-policies'] as const,
  list: (filters: TrainingPolicyFilters) => [...trainingPolicyKeys.all, 'list', filters] as const,
  detail: (id: number) => [...trainingPolicyKeys.all, 'detail', id] as const,
  history: (id: number) => [...trainingPolicyKeys.all, 'history', id] as const
};

export const trainingPoliciesQueryOptions = (filters: TrainingPolicyFilters) =>
  queryOptions({
    queryKey: trainingPolicyKeys.list(filters),
    queryFn: () => getTrainingPolicies(filters)
  });

export const trainingPolicyByIdQueryOptions = (id: number) =>
  queryOptions({
    queryKey: trainingPolicyKeys.detail(id),
    queryFn: () => getTrainingPolicy(id)
  });

export const trainingPolicyHistoryQueryOptions = (id: number) =>
  queryOptions({
    queryKey: trainingPolicyKeys.history(id),
    queryFn: () => getTrainingPolicyHistory(id)
  });
