/// 枚举定义：所有的会话类型分组，用于一级消息分类和路由地址
enum ConversationType {
  noFriend, // 陌生人消息
  system, //系统消息
  newFocus, //新的关注
  interaction, //互动
  order, //订单类通知消息
  groupNotify, //群通知
}

/// 常量映射
class ConversationTypeStatic {
  static const String noFriend = 'noFriend';
  static const String system = 'system';
  static const String newFocus = 'newFocus';
  static const String interaction = 'interaction';
  static const String order = 'order';
  static const String groupNotify = 'groupNotify';
}

extension ConversationTypeExtension on ConversationType {
  String get name {
    switch (this) {
      case ConversationType.noFriend:
        return 'noFriend';
      case ConversationType.system:
        return 'system';
      case ConversationType.newFocus:
        return 'newFocus';
      case ConversationType.interaction:
        return 'interaction';
      case ConversationType.order:
        return 'order';
      case ConversationType.groupNotify:
        return 'groupNotify';
    }
  }
}

conversationTypeFromString(String? type) {
  if (type == null) return null;

  if (type.contains('noFriend')) {
    return ConversationType.noFriend.name;
  } else if (type.contains('system')) {
    return ConversationType.system.name;
  } else if (type.contains('newFocus')) {
    return ConversationType.newFocus.name;
  } else if (type.contains('interaction')) {
    return ConversationType.interaction.name;
  } else if (type.contains('order')) {
    return ConversationType.order.name;
  } else if (type.contains('groupNotify')) {
    return ConversationType.groupNotify.name;
  } else {
    return null;
  }
}
