/**
 * Asset Variants Query Hooks
 *
 * React Query hooks for fetching asset variant data.
 */

import { useQuery } from '@tanstack/react-query';
import axios from 'axios';
import { queryKeys } from '../../lib/queryClient';

interface AssetVariant {
  id: string;
  variant_type: string;
  cdn_url: string;
  width_px: number;
  height_px: number;
  size_mb: number;
  assetId: string;
}

interface AssetVariantListResponse {
  rows: AssetVariant[];
  count: number;
}

/**
 * Fetch list of variants for an asset
 */
export function useAssetVariantsQuery(assetId: string | undefined) {
  return useQuery({
    queryKey: queryKeys.assetVariants.list(assetId || ''),
    queryFn: async (): Promise<AssetVariant[]> => {
      const response = await axios.get<AssetVariantListResponse>(
        `asset_variants?assetId=${assetId}`,
      );
      return response.data.rows;
    },
    enabled: !!assetId,
    staleTime: 5 * 60 * 1000,
  });
}

export default useAssetVariantsQuery;
