import { useQuery, keepPreviousData, } from "@tanstack/react-query"; import { api } from "@/lib/api"; /** 검사 결과 조회 */ export function useInspectionResult(inspectionId: string | undefined) { return useQuery({ queryKey: ["inspection", inspectionId], queryFn: () => api.getInspection(inspectionId!), enabled: !!inspectionId, staleTime: 5 * 60 * 1000, }); } /** 이슈 목록 조회 */ export function useInspectionIssues( inspectionId: string | undefined, category?: string, severity?: string ) { return useQuery({ queryKey: ["inspection-issues", inspectionId, category, severity], queryFn: () => api.getIssues(inspectionId!, { category, severity }), enabled: !!inspectionId, }); } /** 이력 목록 조회 (페이지네이션) */ export function useInspectionHistory(page: number, url?: string) { return useQuery({ queryKey: ["inspection-history", page, url], queryFn: () => api.getInspections({ page, limit: 20, url }), placeholderData: keepPreviousData, }); } /** 트렌드 데이터 조회 */ export function useInspectionTrend(url: string | undefined) { return useQuery({ queryKey: ["inspection-trend", url], queryFn: () => api.getTrend(url!), enabled: !!url, staleTime: 10 * 60 * 1000, }); } /** 최근 검사 이력 (메인 페이지용, 5건) */ export function useRecentInspections() { return useQuery({ queryKey: ["recent-inspections"], queryFn: () => api.getInspections({ page: 1, limit: 5 }), staleTime: 60 * 1000, }); }