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

part 'prayer_request.g.dart';

@HiveType(typeId: 15)
class PrayerRequest extends HiveObject {
  @HiveField(0)
  final String id;

  @HiveField(1)
  final String request;

  @HiveField(2)
  final bool isAnswered;

  @HiveField(3)
  final DateTime createdAt;

  @HiveField(4)
  final DateTime updatedAt;

  PrayerRequest({
    required this.id,
    required this.request,
    this.isAnswered = false,
    required this.createdAt,
    required this.updatedAt,
  });

  PrayerRequest copyWith({
    String? request,
    bool? isAnswered,
    DateTime? updatedAt,
  }) {
    return PrayerRequest(
      id: id,
      request: request ?? this.request,
      isAnswered: isAnswered ?? this.isAnswered,
      createdAt: createdAt,
      updatedAt: updatedAt ?? DateTime.now(),
    );
  }

  factory PrayerRequest.create({required String request}) {
    return PrayerRequest(
      id: const Uuid().v4(),
      request: request,
      createdAt: DateTime.now(),
      updatedAt: DateTime.now(),
    );
  }
}
