import { supabase } from '@/db/supabase';
import { POI } from '@/store/route-store';

export async function getAllCappadociaPOIs(): Promise<POI[]> {
  const { data, error } = await supabase
    .from('places')
    .select('*')
    .eq('region', 'Cappadocia')
    .order('rating', { ascending: false });

  if (error) throw error;
  
  return ((data as any[]) || []).map(p => ({
    id: p.id,
    name: p.name,
    description: p.description,
    latitude: p.latitude,
    longitude: p.longitude,
    category: p.category as any,
    rating: p.rating,
    imageUrl: p.image_url
  }));
}

export async function getPOIById(id: string): Promise<POI | null> {
  const { data, error } = await supabase
    .from('places')
    .select('*')
    .eq('id', id)
    .single();

  if (error) return null;
  
  const p = data as any;
  return {
    id: p.id,
    name: p.name,
    description: p.description,
    latitude: p.latitude,
    longitude: p.longitude,
    category: p.category as any,
    rating: p.rating,
    imageUrl: p.image_url
  };
}
