use serde::{Deserialize, Serialize};
use session::Session;

use super::{
    accessibility::UserAccessibilityConfig, appearance::UserAppearanceConfig,
    notification::UserNotificationConfig, privacy::UserPrivacyConfig,
    profile::UserProfileConfig,
};
use crate::{AppService, error::AppError, session_user};

#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct UserConfigResponse {
    pub profile: UserProfileConfig,
    pub appearance: UserAppearanceConfig,
    pub accessibility: UserAccessibilityConfig,
    pub privacy: UserPrivacyConfig,
    pub notifications: UserNotificationConfig,
}

impl AppService {
    pub async fn user_config(
        &self,
        ctx: &Session,
    ) -> Result<UserConfigResponse, AppError> {
        let user_uid = session_user(ctx)?;
        Ok(UserConfigResponse {
            profile: self.user_profile_config(user_uid).await?,
            appearance: self.user_appearance_config(user_uid).await?,
            accessibility: self.user_accessibility_config(user_uid).await?,
            privacy: self.user_privacy_config(user_uid).await?,
            notifications: self.user_notification_config(user_uid).await?,
        })
    }
}
