import 'package:get_it/get_it.dart'; import 'package:supabase_flutter/supabase_flutter.dart'; import '../models/store_model.dart'; class StoreRepository { final SupabaseClient _client = GetIt.I.get(); /// Crea un nuovo negozio associato alla compagnia dell'utente Future createStore(StoreModel store) async { try { await _client.from('store').insert(store.toJson()); } on PostgrestException catch (e) { // Intercettiamo errori specifici del database throw e.message; } catch (e) { throw 'Errore imprevisto durante la creazione del negozio: $e'; } } /// Recupera tutti i negozi di una determinata compagnia Future> getStoresByCompany(String companyId) async { try { final response = await _client .from('store') .select() .eq('company_id', companyId) .order('created_at'); return (response as List) .map((json) => StoreModel.fromJson(json)) .toList(); } catch (e) { throw 'Errore nel recupero dei negozi'; } } }