import { useQuery } from '@tanstack/react-query';
import { subscriptionApi } from '@/lib/subscription-api';

export const subscriptionKeys = {
  all: ['subscription'] as const,
  plans: () => ['subscription', 'plans'] as const,
  billing: () => ['subscription', 'billing'] as const,
  quota: (metric: string) => ['subscription', 'quota', metric] as const,
};

export function usePlans() {
  return useQuery({
    queryKey: subscriptionKeys.plans(),
    queryFn: () => subscriptionApi.getPlans(),
  });
}

export function useBillingHistory() {
  return useQuery({
    queryKey: subscriptionKeys.billing(),
    queryFn: () => subscriptionApi.getBillingHistory(),
  });
}

export function useQuota(metric: string) {
  return useQuery({
    queryKey: subscriptionKeys.quota(metric),
    queryFn: () => subscriptionApi.checkQuota(metric),
    enabled: !!metric,
  });
}
