/*
 * Copyright 2019, TeamDev. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package io.spine.server.delivery;

import com.google.protobuf.Any;
import io.spine.base.Identifier;
import io.spine.client.EntityId;
import io.spine.string.Stringifiers;
import io.spine.type.TypeUrl;

import static com.google.common.base.Preconditions.checkNotNull;
import static io.spine.base.Identifier.pack;

/**
 * Utilities for working with {@linkplain io.spine.server.delivery.InboxId inbox identifiers}.
 */
final class InboxIds {

    /** Prevents instantiation of this utility class. */
    private InboxIds() {
    }

    /**
     * Obtains the inbox ID from the given entity ID.
     *
     * @param id
     *         the ID of the entity
     * @param entityType
     *         the type of the entity
     * @param <T>
     *         the type of the ID class
     * @return the {@link InboxId}
     */
    static <T> InboxId wrap(T id, TypeUrl entityType) {
        checkNotNull(id);
        checkNotNull(entityType);

        EntityId entityId = EntityId
                .newBuilder()
                .setId(pack(id))
                .vBuild();
        InboxId inboxId = InboxId
                .newBuilder()
                .setEntityId(entityId)
                .setTypeUrl(entityType.value())
                .vBuild();
        return inboxId;
    }

    /**
     * Obtains the entity ID from the given {@link InboxId}.
     *
     * @param inboxId
     *         the ID of the inbox
     * @return the extracted entity ID
     */
    static Object unwrap(InboxId inboxId) {
        checkNotNull(inboxId);
        Any idValue = inboxId.getEntityId()
                             .getId();
        Object unpackedId = Identifier.unpack(idValue);
        return unpackedId;
    }

    /**
     * Creates a new {@code InboxSignalId}.
     *
     * @param targetId the ID of the target to which the signal is dispatched
     * @param uuid the UUID of the signal
     * @return the new instance of @code InboxSignalId}
     */
    static InboxSignalId newSignalId(Object targetId, String uuid) {
        checkNotNull(targetId);
        checkNotNull(uuid);

        String rawValue = uuid + " @" + Stringifiers.toString(targetId);
        InboxSignalId result = InboxSignalId.newBuilder()
                                            .setValue(rawValue)
                                            .build();
        return result;
    }
}

@@ -2782,16 +2782,31 @@
 targetId
+%0A     *        
  the ID 
@@ -2871,16 +2871,31 @@
 ram uuid
+%0A     *        
  the UUI
@@ -2945,16 +2945,17 @@
 ance of 
+%7B
 @code In

Fix the tag and format properly.