/*
 * 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 io.dropwizard.jersey.params.DateTimeParam;
import java.util.List;
import javax.annotation.CheckForNull;
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.QueryParam;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import org.bitcoinj.core.Sha256Hash;
import org.drausin.bitflow.blockchain.api.objects.BlockHeader;
import org.drausin.bitflow.blockchain.api.objects.BlockchainInfo;
import org.drausin.bitflow.service.utils.BitflowService;

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

    /**
     * Gets current information about the blockchain.
     */
    @GET
    @Path("/info")
    @Consumes(MediaType.APPLICATION_JSON)
    @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}")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    BlockHeader getBlockHeader(
            @HeaderParam(HttpHeaders.AUTHORIZATION) String authHeader,
            @PathParam("hash") Sha256Hash hash);

    /**
     * Gets the block header subchain of blocks created within a given time window.
     *
     * @param from (optional) the time after (inclusive) which to get the first block; must be specified if to
     * parameter is not
     * @param to (optional) the time before (exclusive) which to get the last block
     */
    @GET
    @Path("/block/header/subchain/time")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    List<BlockHeader> getBlockHeaderTimeSubchain(
            @HeaderParam(HttpHeaders.AUTHORIZATION) String authHeader,
            @CheckForNull @QueryParam("from") DateTimeParam from,
            @CheckForNull @QueryParam("to") DateTimeParam to);

    /**
     * Gets the block header subchain of blocks created within a given height range, relative to the current best block.
     *
     * @param from the height above (inclusive) which to get the first block
     * @param to the height below (inclusive) which to get the last block
     */
    @GET
    @Path("/block/header/subchain/height")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    List<BlockHeader> getBlockHeaderHeightSubchain(
            @HeaderParam(HttpHeaders.AUTHORIZATION) String authHeader,
            @CheckForNull @QueryParam("from") long from,
            @CheckForNull @QueryParam("to") long to);
}

@@ -1468,92 +1468,8 @@
 o%22)%0A
-    @Consumes(MediaType.APPLICATION_JSON)%0A    @Produces(MediaType.APPLICATION_JSON)%0A
     
@@ -1502,16 +1502,16 @@
 inInfo(%0A
+
         
@@ -1726,16 +1726,21 @@
 /header/
+hash/
 %7Bhash%7D%22)
@@ -1748,86 +1748,361 @@
     
-@Consumes(MediaType.APPLICATION_JSON)%0A    @Produces(MediaType.APPLICATION_JSON
+BlockHeader getBlockHeader(%0A            @HeaderParam(HttpHeaders.AUTHORIZATION) String authHeader,%0A            @CheckForNull @PathParam(%22hash%22) Sha256Hash hash);%0A%0A    /**%0A     * Gets the block header at a given block height.%0A     *%0A     * @param height the height of the block in the blockchain%0A     */%0A    @GET%0A    @Path(%22/block/header/height/%7Bheight%7D%22
 )%0A  
@@ -2219,41 +2219,53 @@
    @
-PathParam(%22hash%22) Sha256Hash hash
+CheckForNull @PathParam(%22height%22) long height
 );%0A%0A
@@ -2644,92 +2644,8 @@
 e%22)%0A
-    @Consumes(MediaType.APPLICATION_JSON)%0A    @Produces(MediaType.APPLICATION_JSON)%0A
     
@@ -3187,32 +3187,32 @@
     */%0A    @GET%0A
+
     @Path(%22/bloc
@@ -3242,92 +3242,8 @@
 t%22)%0A
-    @Consumes(MediaType.APPLICATION_JSON)%0A    @Produces(MediaType.APPLICATION_JSON)%0A
     

remove redundant consumes/produces annocations, overload getBlockHeader() for header hash, and update getBlockHeader GET path