import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../models/service.dart';
import 'supabase_provider.dart';

final servicesProvider = StreamProvider<List<Service>>((ref) {
  final client = ref.watch(supabaseClientProvider);
  return client
      .from('services')
      .stream(primaryKey: ['id'])
      .order('name')
      .map((rows) => rows.map((r) => Service.fromMap(r)).toList());
});

final servicesOnceProvider = FutureProvider<List<Service>>((ref) async {
  final client = ref.watch(supabaseClientProvider);
  final rows = await client.from('services').select().order('name');
  return (rows as List<dynamic>)
      .map((r) => Service.fromMap(r as Map<String, dynamic>))
      .toList();
});
