/*
 * 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.
 */

/*
 * 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.client.objects;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.drausin.bitflow.blockchain.api.objects.BlockchainResult;
import org.immutables.value.Value;

/**
 * The RPC request to the bitcoin daemon.
 *
 * @see <a href="https://bitcoin.org/en/developer-reference#remote-procedure-calls-rpcs">Bitcoin RPCs</a>
 * @author dwulsin
 */
@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@JsonDeserialize(as = ImmutableBitcoindRpcResponse.class)
public abstract class BitcoindRpcResponse {

    @Value.Parameter
    @JsonProperty("result")
    public abstract BlockchainResult getResult();

    @Value.Parameter
    @JsonProperty("error")
    public abstract BitcoindRpcResponseError getError();

    @Value.Parameter
    @JsonProperty("id")
    public abstract String getId();

    public static BitcoindRpcResponse of(BlockchainResult result, BitcoindRpcResponseError error, String id) {
        return ImmutableBitcoindRpcResponse.of(result, error, id);
    }
}

@@ -1295,16 +1295,61 @@
 ialize;%0A
+import com.google.common.base.Preconditions;%0A
 import o
@@ -1493,16 +1493,35 @@
 mon.%0A *%0A
+ * @author dwulsin%0A
  * @see 
@@ -1618,35 +1618,16 @@
 PCs%3C/a%3E%0A
- * @author dwulsin%0A
  */%0A@Val
@@ -2285,11 +2285,420 @@
 );%0A    %7D
+%0A%0A    public final void validate(Class%3C? extends BlockchainResult%3E resultType) %7B%0A        Preconditions.checkNotNull(getError(), String.format(%22reponse error: %7B%7D%22, getError()));%0A        Preconditions.checkState(getResult().getClass().equals(resultType),%0A                String.format(%22unexpected response type: expected was %7B%7D, actual is %7B%7D%22, getResult().getClass(),%0A                        resultType));%0A    %7D
 %0A%7D%0A

add response validation