import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:uuid/uuid.dart';

class RefManufactorers {
  final SupabaseClient _supabase = Supabase.instance.client;

  Future<List> getList() async {
    try {
      final data = await _supabase
          .from('ref_manufactorers')
          .select('manufactorer_name')
          .order('manufactorer_name', ascending: true);
      return data.toList();
    } catch (e) {
      return [];
    }
  }

  Future<String> getUUID(String name) async {
    try {
      final data =
          await _supabase.from('ref_manufactorers').select('ref_manufactorers_uuid').eq('manufactorer_name', name);
      return data.first['ref_manufactorers_uuid'].toString();
    } catch (e) {
      return '';
    }
  }

  Future<bool> postManufactorer(String name, String address) async {
    try {
      final genericUUID = Uuid().v4();

      await _supabase
          .from('ref_manufactorers')
          .insert({'ref_manufactorers_uuid': genericUUID, 'manufactorer_name': name, 'manufactorer_address': address});
      return true;
    } catch (e) {
      return false;
    }
  }
}
