import { queryOptions } from '@tanstack/react-query'
import { api } from '@/lib/api-client'

export interface ModuleConfig {
  id: string
  slug: string
  name: string
  description: string | null
  licensed: boolean
  enabled: boolean
  createdAt: string
  updatedAt: string
}

export const moduleKeys = {
  list: ['modules'] as const,
}

export function moduleListOptions() {
  return queryOptions({
    queryKey: moduleKeys.list,
    queryFn: () => api.get<{ data: ModuleConfig[] }>('/v1/modules'),
  })
}

export const moduleMutations = {
  toggle: (slug: string, enabled: boolean) => api.patch<ModuleConfig>(`/v1/modules/${slug}`, { enabled }),
}
