import { useQuery } from '@tanstack/react-query';
import { api } from '@/shared/lib/apiClient';

/**
 * useStudioProperties — Studio Pillar property listing
 */
export function useStudioProperties() {
  const query = useQuery({
    queryKey: ['studio-properties'],
    queryFn:  () => api.get<StudioProperty[]>('/inventory/properties'),
    staleTime: 120_000,
  });
  return { properties: query.data ?? [], isLoading: query.isLoading };
}

/**
 * useProperty — single property entity with full details
 */
export function useProperty(propertyId: string) {
  const query = useQuery({
    queryKey: ['property', propertyId],
    queryFn:  () => api.get<PropertyDetail>(`/inventory/properties/${propertyId}`),
    staleTime: 120_000,
    enabled:  !!propertyId,
  });
  return { property: query.data, isLoading: query.isLoading };
}

// ── Types ────────────────────────────────────────────────────
export interface StudioProperty {
  id: string;
  name: string;
  location: string;
  priceRange?: string;
  thumbnailUrl?: string;
  availableUnits?: number;
}

export interface PropertyDetail {
  id: string;
  name: string;
  config: string;
  area: string;
  price: string;
  description?: string;
  thumbnailUrl?: string;
  interiorImageUrl?: string;
  modelUrl?: string;          // GLB/GLTF for R3F
  images?: string[];
  amenities?: string[];
}
