/**
 * React Query Key Factory
 * 일관된 쿼리 키 관리를 위한 팩토리 함수들
 */

export const queryKeys = {
  // 카테고리 관련 쿼리 키
  categories: {
    all: ["categories"] as const,
    lists: () => [...queryKeys.categories.all, "list"] as const,
    list: (filters?: { active?: boolean; search?: string }) => [...queryKeys.categories.lists(), filters] as const,
    infinite: (filters?: { active?: boolean; search?: string }) =>
      [...queryKeys.categories.all, "infinite", filters] as const,
    infiniteList: (filters?: { active?: boolean; search?: string }) =>
      [...queryKeys.categories.all, "infiniteList", filters] as const,
    details: () => [...queryKeys.categories.all, "detail"] as const,
    detail: (categoryCode: string) => [...queryKeys.categories.details(), categoryCode] as const,
  },

  // 코드 관련 쿼리 키
  codes: {
    all: ["codes"] as const,
    lists: () => [...queryKeys.codes.all, "list"] as const,
    list: (categoryCode: string, filters?: { active?: boolean; search?: string }) =>
      [...queryKeys.codes.lists(), categoryCode, filters] as const,
    infinite: (categoryCode: string, filters?: { active?: boolean; search?: string }) =>
      [...queryKeys.codes.all, "infinite", categoryCode, filters] as const,
    infiniteList: (categoryCode: string, filters?: { active?: boolean; search?: string }) =>
      [...queryKeys.codes.all, "infiniteList", categoryCode, filters] as const,
    details: () => [...queryKeys.codes.all, "detail"] as const,
    detail: (categoryCode: string, codeValue: string) =>
      [...queryKeys.codes.details(), categoryCode, codeValue] as const,
  },

  // 옵션 관련 쿼리 키 (향후 화면관리 연계용)
  options: {
    all: ["options"] as const,
    byCategory: (categoryCode: string) => [...queryKeys.options.all, categoryCode] as const,
  },

  // 검증 관련 쿼리 키
  validation: {
    all: ["validation"] as const,
    categoryDuplicate: (field: string, value: string, excludeCode?: string) =>
      [...queryKeys.validation.all, "category", field, value, excludeCode] as const,
    codeDuplicate: (categoryCode: string, field: string, value: string, excludeCode?: string) =>
      [...queryKeys.validation.all, "code", categoryCode, field, value, excludeCode] as const,
  },
} as const;
