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

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

  Future<List> getPrescriptions(String uuid) async {
    try {
      final data = await _supabase.from('prescriptions').select('prescriptions_uuid').eq('user_id', uuid);
      return data.toList();
    } catch (e) {
      return [];
    }
  }

  Future<bool> postPrescription(String userId, String medicineUuid) async {
    try {
      final prescriptionUUID = Uuid().v4();
      await _supabase
          .from('prescriptions')
          .insert({'prescriptions_uuid': prescriptionUUID, 'user_id': userId, 'ref_medicine_uuid': medicineUuid});
      return true;
    } catch (e) {
      return false;
    }
  }
}
