use actix_web::{web, HttpResponse, Responder};
use crate::app_state::AppState;
use bamboo_notification::NotificationPreferences;
pub async fn get_preferences(state: web::Data<AppState>) -> impl Responder {
HttpResponse::Ok().json(state.notification_service.preferences())
}
pub async fn update_preferences(
state: web::Data<AppState>,
body: web::Json<NotificationPreferences>,
) -> impl Responder {
let prefs = body.into_inner();
match state.notification_service.set_preferences(prefs.clone()) {
Ok(()) => HttpResponse::Ok().json(prefs),
Err(error) => HttpResponse::InternalServerError().json(serde_json::json!({
"error": format!("Failed to persist notification preferences: {error}")
})),
}
}