import 'package:cloud_firestore/cloud_firestore.dart';

class Pet {
  final String id;
  final String ownerId;
  final String name;
  final String species; // "강아지", "고양이", etc.
  final String breed; // "말티즈", "코숏", etc.
  final String gender; // "남아", "여아"
  final bool isNeutered;
  final DateTime? birthDate;
  final bool isDateUnknown;
  final String? registrationNumber;
  final String? profileImageUrl;
  final double? weight; // 체중 (kg)
  final List<String> diseases;
  final List<String> pastDiseases;
  final List<String> healthConcerns;
  final DateTime createdAt;

  Pet({
    required this.id,
    required this.ownerId,
    required this.name,
    required this.species,
    required this.breed,
    required this.gender,
    required this.isNeutered,
    this.birthDate,
    required this.isDateUnknown,
    this.registrationNumber,
    this.profileImageUrl,
    this.weight,
    required this.diseases,
    required this.pastDiseases,
    required this.healthConcerns,
    required this.createdAt,
  });

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'ownerId': ownerId,
      'name': name,
      'species': species,
      'breed': breed,
      'gender': gender,
      'isNeutered': isNeutered,
      'birthDate': birthDate != null ? Timestamp.fromDate(birthDate!) : null,
      'isDateUnknown': isDateUnknown,
      'registrationNumber': registrationNumber,
      'profileImageUrl': profileImageUrl,
      'weight': weight,
      'diseases': diseases,
      'pastDiseases': pastDiseases,
      'healthConcerns': healthConcerns,
      'createdAt': Timestamp.fromDate(createdAt),
    };
  }

  factory Pet.fromMap(Map<String, dynamic> map) {
    return Pet(
      id: map['id'] ?? '',
      ownerId: map['ownerId'] ?? '',
      name: map['name'] ?? '',
      species: map['species'] ?? '',
      breed: map['breed'] ?? '',
      gender: map['gender'] ?? '',
      isNeutered: map['isNeutered'] ?? false,
      birthDate: map['birthDate'] != null
          ? (map['birthDate'] as Timestamp).toDate()
          : null,
      isDateUnknown: map['isDateUnknown'] ?? false,
      registrationNumber: map['registrationNumber'],
      profileImageUrl: map['profileImageUrl'],
      weight: map['weight']?.toDouble(),
      diseases: List<String>.from(map['diseases'] ?? []),
      pastDiseases: List<String>.from(map['pastDiseases'] ?? []),
      healthConcerns: List<String>.from(map['healthConcerns'] ?? []),
      createdAt: (map['createdAt'] as Timestamp).toDate(),
    );
  }
}
