use newton_prover_core::config::{key::EcdsaKey, ConfigLoader};
use serde::{Deserialize, Serialize};

/// Aggregator Config
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct NewtonCliConfig {
    /// Ethereum RPC URL
    pub eth_rpc_url: String,
    /// Newton RPC URL
    pub newton_rpc_url: String,
    /// Signer
    pub signer: EcdsaKey,
    /// Dashboard bearer token for API authentication
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub dashboard_bearer_token: Option<String>,
    /// Dashboard API base URL
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub dashboard_api_base_url: Option<String>,
}

// Implement ConfigLoader trait - provides load_config method automatically
impl ConfigLoader for NewtonCliConfig {
    const FILE_NAME: &'static str = "newton-cli";
    const ENV_PREFIX: &'static str = "NEWTON_CLI";
}

impl NewtonCliConfig {
    /// Set eth rpc url
    pub fn set_eth_rpc_url(&mut self, eth_rpc_url: String) {
        self.eth_rpc_url = eth_rpc_url;
    }

    /// Set newton rpc url
    pub fn set_newton_rpc_url(&mut self, newton_rpc_url: String) {
        self.newton_rpc_url = newton_rpc_url;
    }

    /// Set signer
    pub fn set_signer(&mut self, signer: EcdsaKey) {
        self.signer = signer;
    }

    /// Set dashboard bearer token
    pub fn set_dashboard_bearer_token(&mut self, token: Option<String>) {
        self.dashboard_bearer_token = token;
    }

    /// Set dashboard API base URL
    pub fn set_dashboard_api_base_url(&mut self, url: Option<String>) {
        self.dashboard_api_base_url = url;
    }
}
