package com.kryptnostic.v2.storage.models;

import java.util.Map;
import java.util.UUID;

import javax.annotation.concurrent.Immutable;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Optional;

@Immutable
public class ObjectTreeLoadResponse {
    private final Map<UUID, ObjectMetadataEncryptedNode> omTree;
    private final Optional<String>                       nextPage;
    private static final String                          template = "levels/%s/%d/%s/%d";

    @JsonCreator
    public ObjectTreeLoadResponse(
            @JsonProperty( "objectMetadataTree" ) Map<UUID, ObjectMetadataEncryptedNode> results,
            @JsonProperty( "nextPage" ) Optional<String> nextPage) {
        this.omTree = results;
        this.nextPage = nextPage;
    }

    public static String nextPage(
            UUID aclId,
            int pageSize,
            VersionedObjectKey latestObject ) {
        return String.format( template,
                aclId.toString(),
                pageSize,
                latestObject.getObjectId().toString(),
                latestObject.getVersion() );
    }

    @JsonProperty( "objectMetadataTree" )
    public Map<UUID, ObjectMetadataEncryptedNode> getOmTree() {
        return omTree;
    }

    @JsonProperty( "nextPage" )
    public Optional<String> getNextPage() {
        return nextPage;
    }

}

@@ -528,16 +528,17 @@
 late = %22
+/
 levels/%25

add a leading /