import '../utils/app_time.dart';

class NotificationItem {
  NotificationItem({
    required this.id,
    required this.userId,
    required this.actorId,
    required this.ticketId,
    required this.taskId,
    required this.messageId,
    required this.type,
    required this.createdAt,
    required this.readAt,
  });

  final String id;
  final String userId;
  final String? actorId;
  final String? ticketId;
  final String? taskId;
  final int? messageId;
  final String type;
  final DateTime createdAt;
  final DateTime? readAt;

  bool get isUnread => readAt == null;

  factory NotificationItem.fromMap(Map<String, dynamic> map) {
    return NotificationItem(
      id: map['id'] as String,
      userId: map['user_id'] as String,
      actorId: map['actor_id'] as String?,
      ticketId: map['ticket_id'] as String?,
      taskId: map['task_id'] as String?,
      messageId: map['message_id'] as int?,
      type: map['type'] as String? ?? 'mention',
      createdAt: AppTime.parse(map['created_at'] as String),
      readAt: map['read_at'] == null
          ? null
          : AppTime.parse(map['read_at'] as String),
    );
  }
}
