// missionMATCH React Query hooks over the tool's namespace client. Keys are prefixed with the tool name // so the three tools never collide in the shared query cache. import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { missionApi } from './api' import type { AdoptForecastInput } from '../../lib/types' export function useMissionCommandCenter() { return useQuery({ queryKey: ['missionmatch', 'command-center'], queryFn: missionApi.commandCenter }) } export function useMissionIntelligence() { return useQuery({ queryKey: ['missionmatch', 'intelligence'], queryFn: () => missionApi.candidateIntelligence() }) } export function useMissionRequirements() { return useQuery({ queryKey: ['missionmatch', 'requirements'], queryFn: missionApi.requirements }) } export function useWhoCanSupport(requirementId: string | null) { return useQuery({ queryKey: ['missionmatch', 'support', requirementId], queryFn: () => missionApi.whoCanSupport(requirementId as string), enabled: !!requirementId, }) } // useMissionAdoptForecast turns a forecast into a requirement, then refreshes the rollups so the new // requirement flows through the shared engine into coverage and readiness. export function useMissionAdoptForecast() { const qc = useQueryClient() return useMutation({ mutationFn: (v: { recordID: string; input: AdoptForecastInput }) => missionApi.adoptForecast(v.recordID, v.input), onSuccess: () => { void qc.invalidateQueries({ queryKey: ['missionmatch', 'command-center'] }) void qc.invalidateQueries({ queryKey: ['missionmatch', 'requirements'] }) }, }) }