use crate::secret_client::SecretClient;
use std::sync::Arc;

#[cfg(feature = "builder")]
use crate::builder::AppStateBuilder;

/// Shared application state for a PyWatt module.
///
/// Contains SDK-provided fields (`module_id`, `orchestrator_api`, `secret_client`)
/// plus user-defined state of type `T`.
#[derive(Clone, Debug)]
pub struct AppState<T> {
    module_id: String,
    orchestrator_api: String,
    secret_client: Arc<SecretClient>,
    /// User-provided application state
    pub user_state: T,
}

impl<T> AppState<T> {
    /// Create a new `AppState` with the given SDK context and user state.
    pub fn new(
        module_id: String,
        orchestrator_api: String,
        secret_client: Arc<SecretClient>,
        user_state: T,
    ) -> Self {
        Self {
            module_id,
            orchestrator_api,
            secret_client,
            user_state,
        }
    }

    /// Returns the module's ID.
    pub fn module_id(&self) -> &str {
        &self.module_id
    }

    /// Returns the orchestrator API URL.
    pub fn orchestrator_api(&self) -> &str {
        &self.orchestrator_api
    }

    /// Returns the configured `SecretClient` instance.
    pub fn secret_client(&self) -> &Arc<SecretClient> {
        &self.secret_client
    }

    /// Creates a new `AppStateBuilder` for fluent API construction.
    #[cfg(feature = "builder")]
    pub fn builder() -> AppStateBuilder<T> {
        AppStateBuilder::new()
    }
}
