public static BsonValue encodeSingleValue(@Nullable Object value) {
        return switch (value) {
            case null -> BsonNull.VALUE;
            case Byte val -> new BsonInt32(val);
            case Short val -> new BsonInt32(val);
            case Integer val -> new BsonInt32(val);
            case Long val -> new BsonInt64(val);
            case Float val -> new BsonDouble(val);
            case Double val -> new BsonDouble(val);
            case Character val -> new BsonString(val.toString());
            case Boolean val -> val
                    ? BsonBoolean.TRUE
                    : BsonBoolean.FALSE;
            case String val -> new BsonString(val);
            case Date val -> new BsonDateTime(val.getTime());
            case byte[] val -> new BsonBinary(val);
            case BsonValue val -> val;
            default -> {
                Class<?> clazz = value.getClass();
                if (clazz.isEnum()) {
                    Enum<?> element = (Enum<?>) value;
                    yield new BsonInt32(element.ordinal());
                }
                EncoderContext encoderContext = EncoderContext.builder()
                        .build();
                BsonDocument document = new BsonDocument();
                BsonWriter writer = new BsonDocumentWriter(document);
                EntityCodec codec = (EntityCodec) CodecPool.CODEC_REGISTRY.get(clazz);
                codec.encode(writer, value, encoderContext);
                yield document;
            }
        };
    }
TODO: unify the logic of {@link #encode} and {@link #write}
turms-server-common/src/main/java/im/turms/server/common/storage/mongo/codec/CodecUtil.java