use crate::AppConfig;

impl AppConfig {
    pub fn pr_rpc_addr(&self) -> anyhow::Result<String> {
        self.env
            .get("APP_PR_RPC_ADDR")
            .map(|v| v.trim().to_string())
            .ok_or_else(|| anyhow::anyhow!("APP_PR_RPC_ADDR not set"))
    }

    pub fn pr_rpc_port(&self) -> anyhow::Result<u16> {
        if let Some(port) = self.env.get("APP_PR_RPC_PORT") {
            return Ok(port.parse::<u16>()?);
        }
        Ok(8040)
    }

    pub fn pr_http_port(&self) -> anyhow::Result<u16> {
        if let Some(port) = self.env.get("APP_PR_HTTP_PORT") {
            return Ok(port.parse::<u16>()?);
        }
        Ok(8041)
    }
}
