/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.drausin.bitflow.blockchain.api;

import com.google.common.base.Optional;
import java.util.Map;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import org.drausin.bitflow.blockchain.BlockchainInfo;

@Path("/blockchain")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public interface BlockchainService {

    /**
     * Gets current information about the blockchain.
     */
    @GET
    @Path("/info")
    @Produces(MediaType.APPLICATION_JSON)
    BlockchainInfo getBlockchainInfo(
            @HeaderParam(HttpHeaders.AUTHORIZATION) String authHeader);


    /**
     * Gets the block header for a given block hash.
     *
     * @param hash the hash of the block
     */
    @GET
    @Path("/block/header/{hash}")
    @Produces(MediaType.APPLICATION_JSON)
    Optional<Map<String, Object>> getBlockHeader(
            @HeaderParam(HttpHeaders.AUTHORIZATION) String authHeader,
            @PathParam("hash") String hash);

    // TODO: getBlockTimeSubchain(long fromTime, long toTime)

    // TODO: getBlockTimeSubchain(Date fromDate, Date toDate)

    // TODO: getBlockHeightSubchain(long fromHeight, long toHeight)
}

@@ -612,61 +612,60 @@
 ort 
-com.google.common.base.Optional;%0Aimport java.util.Map
+java.util.List;%0Aimport javax.annotation.CheckForNull
 ;%0Aim
@@ -827,24 +827,55 @@
 s.Produces;%0A
+import javax.ws.rs.QueryParam;%0A
 import javax
@@ -934,16 +934,67 @@
 iaType;%0A
+import org.drausin.bitflow.blockchain.BlockHeader;%0A
 import o
@@ -1038,16 +1038,47 @@
 ainInfo;
+%0Aimport org.joda.time.DateTime;
 %0A%0A@Path(
@@ -1457,17 +1457,16 @@
 ader);%0A%0A
-%0A
     /**%0A
@@ -1667,37 +1667,19 @@
     
-Optional%3CMap%3CString, Object%3E%3E
+BlockHeader
  get
@@ -1817,78 +1817,442 @@
    /
-/ TODO: getBlockTimeSubchain(long fromTime, long toTime)%0A%0A    // TODO:
+**%0A     * Gets the block header subchain of blocks created within a given time window.%0A     *%0A     * @param from (optional) the time after (inclusive) which to get the first block; must be specified if to%0A     * parameter is not%0A     * @param to (optional) the time before (exclusive) which to get the last block%0A     */%0A    @GET%0A    @Path(%22/block/header/subchain/time%22)%0A    @Produces(MediaType.APPLICATION_JSON)%0A    List%3CBlockHeader%3E
  get
@@ -2256,16 +2256,22 @@
 getBlock
+Header
 TimeSubc
@@ -2279,49 +2279,610 @@
 ain(
-Date 
+%0A            @HeaderParam(HttpHeaders.AUTHORIZATION) String authHeader,%0A            @CheckForNull @QueryParam(%22
 from
+%22) 
 Date
-, Date toDate)%0A%0A    // TODO:
+Time from,%0A            @CheckForNull @QueryParam(%22to%22) DateTime to);%0A%0A    /**%0A     * Gets the block header subchain of blocks created within a given height range, relative to the current best block.%0A     *%0A     * @param from the height above (inclusive) which to get the first block%0A     * @param to the height below (exclusive) which to get the last block%0A     */%0A    @GET%0A    @Path(%22/block/header/subchain/height%22)%0A    @Produces(MediaType.APPLICATION_JSON)%0A    List%3CBlockHeader%3E
  get
@@ -2888,16 +2888,22 @@
 tBlockHe
+aderHe
 ightSubc
@@ -2911,38 +2911,197 @@
 ain(
-long fromHeight, long toHeight)
+%0A            @HeaderParam(HttpHeaders.AUTHORIZATION) String authHeader,%0A            @CheckForNull @QueryParam(%22from%22) DateTime from,%0A            @CheckForNull @QueryParam(%22to%22) DateTime to);
 %0A%7D%0A

add block subchain endpoint definitions