use crate::client::AmagiClient;
use crate::config::ServeConfig;
use crate::error::AppError;
use super::runtime::{PlatformServeMode, ServerRuntimeConfig};
use crate::catalog::Platform;
#[derive(Debug, Clone)]
pub struct AppState {
pub app_name: &'static str,
pub version: &'static str,
pub serve: ServeConfig,
pub client: AmagiClient,
pub runtime: ServerRuntimeConfig,
pub proxy_client: reqwest::Client,
}
impl AppState {
pub fn new(
app_name: &'static str,
version: &'static str,
serve: ServeConfig,
client: AmagiClient,
runtime: ServerRuntimeConfig,
) -> Result<Self, AppError> {
let proxy_client = runtime.build_proxy_client()?;
Ok(Self {
app_name,
version,
serve,
client,
runtime,
proxy_client,
})
}
pub fn platform_mode(&self, platform: Platform) -> PlatformServeMode {
self.runtime.platform_mode(platform)
}
pub fn is_platform_published(&self, platform: Platform) -> bool {
self.runtime.is_platform_published(platform)
}
pub fn platform_upstream(&self, platform: Platform) -> Option<&str> {
self.runtime.platform_upstream(platform)
}
pub const fn proxy_max_hops(&self) -> u32 {
self.runtime.proxy_max_hops()
}
}