import '../../../core/constants.dart';

class RequestHistoryEntry {
  final String notificationId;
  final String sessionId;
  final DateTime notifiedAt;
  final DateTime? respondedAt;
  final RequestResponse? response;
  final String sessionStatus;
  final String customerCallName;
  final TopicSensitivity topicSensitivity;

  const RequestHistoryEntry({
    required this.notificationId,
    required this.sessionId,
    required this.notifiedAt,
    required this.respondedAt,
    required this.response,
    required this.sessionStatus,
    required this.customerCallName,
    required this.topicSensitivity,
  });

  bool get isPending =>
      response == null && sessionStatus == SessionStatus.pendingAcceptance;

  factory RequestHistoryEntry.fromJson(Map<String, dynamic> json) {
    return RequestHistoryEntry(
      notificationId: json['notification_id'] as String,
      sessionId: json['session_id'] as String,
      notifiedAt: DateTime.parse(json['notified_at'] as String).toLocal(),
      respondedAt: json['responded_at'] != null
          ? DateTime.parse(json['responded_at'] as String).toLocal()
          : null,
      response: RequestResponse.fromString(json['response'] as String?),
      sessionStatus: json['session_status'] as String? ?? '',
      customerCallName: json['customer_call_name'] as String? ?? 'Anonim',
      topicSensitivity:
          TopicSensitivity.fromString(json['topic_sensitivity'] as String?),
    );
  }
}
