class SupportChat {
  final String id;
  final String userId;
  final String status; // OPEN, CLOSED
  final String? lastMessageAt;
  final String? lastMessageText;
  final int userUnreadCount;
  final int adminUnreadCount;
  final String createdAt;
  final String updatedAt;

  const SupportChat({
    required this.id,
    required this.userId,
    required this.status,
    this.lastMessageAt,
    this.lastMessageText,
    required this.userUnreadCount,
    required this.adminUnreadCount,
    required this.createdAt,
    required this.updatedAt,
  });

  factory SupportChat.fromJson(Map<String, dynamic> json) {
    return SupportChat(
      id: json['id'] as String,
      userId: json['userId'] as String,
      status: json['status'] as String? ?? 'OPEN',
      lastMessageAt: json['lastMessageAt'] as String?,
      lastMessageText: json['lastMessageText'] as String?,
      userUnreadCount: json['userUnreadCount'] as int? ?? 0,
      adminUnreadCount: json['adminUnreadCount'] as int? ?? 0,
      createdAt: json['createdAt'] as String,
      updatedAt: json['updatedAt'] as String,
    );
  }

  bool get isClosed => status == 'CLOSED';
}

class SupportMessage {
  final String id;
  final String chatId;
  final String senderId;
  final String senderRole;
  final String content;
  final String createdAt;

  const SupportMessage({
    required this.id,
    required this.chatId,
    required this.senderId,
    required this.senderRole,
    required this.content,
    required this.createdAt,
  });

  factory SupportMessage.fromJson(Map<String, dynamic> json) {
    return SupportMessage(
      id: json['id'] as String,
      chatId: json['chatId'] as String,
      senderId: json['senderId'] as String,
      senderRole: json['senderRole'] as String? ?? 'USER',
      content: json['content'] as String,
      createdAt: json['createdAt'] as String,
    );
  }
}

class SupportPagination {
  final int page;
  final int limit;
  final int total;
  final int pages;

  const SupportPagination({
    required this.page,
    required this.limit,
    required this.total,
    required this.pages,
  });

  factory SupportPagination.fromJson(Map<String, dynamic> json) {
    return SupportPagination(
      page: json['page'] as int? ?? 1,
      limit: json['limit'] as int? ?? 50,
      total: json['total'] as int? ?? 0,
      pages: json['pages'] as int? ?? 1,
    );
  }

  bool get hasMore => page < pages;
}
