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

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

  Future<List> getList() async {
    final data = await _supabase.from('ref_types').select('type_name').order('type_name', ascending: true);
    return data.toList();
  }

  Future<String> getUUID(String name) async {
    final data = await _supabase.from('ref_types').select('ref_types_uuid').eq('type_name', name);
    return data.first['ref_types_uuid'].toString();
  }

  Future<void> postType(String name) async {
    final typeUUID = Uuid().v4();

    await _supabase.from('ref_types').insert({'ref_types_uuid': typeUUID, 'type_name': name});
  }
}
