// lib/app/models/patient_model.dart
import 'package:cloud_firestore/cloud_firestore.dart';

class PatientModel {
  final String id;
  final String namePatient;
  final String nameGuardian;
  final String deviceId;
  final String roomId;
  final String? userId; // Firebase Auth UID

  PatientModel({
    required this.id,
    required this.namePatient,
    required this.nameGuardian,
    required this.deviceId,
    required this.roomId,
    this.userId,
  });

  // From Firestore
  factory PatientModel.fromFirestore(DocumentSnapshot doc) {
    final data = doc.data() as Map<String, dynamic>;
    return PatientModel(
      id: doc.id,
      namePatient: data['name_patient'] ?? '',
      nameGuardian: data['name_guardian'] ?? '',
      deviceId: data['device_id'] ?? '',
      roomId: data['room_id'] ?? '',
      userId: data['user_id'],
    );
  }

  // To Firestore
  Map<String, dynamic> toFirestore() {
    return {
      'name_patient': namePatient,
      'name_guardian': nameGuardian,
      'device_id': deviceId,
      'room_id': roomId,
      if (userId != null) 'user_id': userId,
    };
  }
}