// Copyright (c) Subzero Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use serde::{Deserialize, Serialize};

use super::rpc_response_context::RpcResponseContext;

/// The 'inner' response message for a GetLatestBlockhash request.
/// Also includes the response context.
#[derive(Serialize, Deserialize)]
pub struct GetLatestBlockhashResponse {
    pub context: RpcResponseContext,
    pub value: GetLatestBlockhashValue,
}

impl GetLatestBlockhashResponse {
    pub fn new(slot: u64, blockhash: String, last_valid_block_height: u64) -> Self {
        Self {
            context: RpcResponseContext::new(slot),
            value: GetLatestBlockhashValue::new(blockhash, last_valid_block_height),
        }
    }
}

#[derive(Serialize, Deserialize)]
pub struct GetLatestBlockhashValue {
    pub blockhash: String,
    #[serde(rename = "lastValidBlockHeight")]
    pub last_valid_block_height: u64,
}

impl GetLatestBlockhashValue {
    pub fn new(blockhash: String, last_valid_block_height: u64) -> Self {
        Self {
            blockhash,
            last_valid_block_height,
        }
    }
}

/// Request for getLatestBlockhash RPC call
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct GetLatestBlockhashRequest {}

impl GetLatestBlockhashRequest {
    pub fn new() -> Self {
        Self {}
    }
}
