use axum::{extract::{Extension, Path}, Json};

use crate::{app_state::{AppState, LocalizationBundleSnapshot}, error::AppError};

pub async fn bundle(
    Path(locale_code): Path<String>,
    Extension(state): Extension<AppState>,
) -> Result<Json<LocalizationBundleSnapshot>, AppError> {
    let Some(bundle) = state.localization_bundle(&locale_code).await else {
        return Err(AppError::not_found("Localization bundle not found"));
    };

    Ok(Json(bundle))
}
