import { queryOptions } from '@tanstack/react-query';
import {
  getTrainingMatrixById,
  getTrainingMatrixCompliance,
  getTrainingMatrices,
  getTrainingMatrixOptions
} from './service';
import type { TrainingMatrix, TrainingMatrixFilters } from './types';

export type { TrainingMatrix };

const trainingMatrixAllKey = ['training-matrix'] as const;

export const trainingMatrixKeys = {
  all: trainingMatrixAllKey,
  list: (filters: TrainingMatrixFilters) => [...trainingMatrixAllKey, 'list', filters] as const,
  detail: (id: number) => [...trainingMatrixAllKey, 'detail', id] as const,
  options: [...trainingMatrixAllKey, 'options'] as const,
  compliance: [...trainingMatrixAllKey, 'compliance'] as const
};

export const trainingMatricesQueryOptions = (filters: TrainingMatrixFilters) =>
  queryOptions({
    queryKey: trainingMatrixKeys.list(filters),
    queryFn: () => getTrainingMatrices(filters)
  });

export const trainingMatrixByIdOptions = (id: number) =>
  queryOptions({
    queryKey: trainingMatrixKeys.detail(id),
    queryFn: () => getTrainingMatrixById(id)
  });

export const trainingMatrixOptionsQueryOptions = () =>
  queryOptions({
    queryKey: trainingMatrixKeys.options,
    queryFn: getTrainingMatrixOptions
  });

export const trainingMatrixComplianceQueryOptions = () =>
  queryOptions({
    queryKey: trainingMatrixKeys.compliance,
    queryFn: getTrainingMatrixCompliance
  });
