use crate::{ApiResponse, error::ApiError};
use actix_web::{HttpResponse, Result, web};
use service::AppService;
use session::Session;

#[utoipa::path(
    get,
    path = "/api/users/me/notifications/preferences",
    responses(
        (status = 200, description = "Get notification preferences", body = ApiResponse<service::user::notification::NotificationPreferencesResponse>),
        (status = 401, description = "Unauthorized"),
),
    tag = "User"
)]
pub async fn get_notification_preferences(
    service: web::Data<AppService>,
    session: Session,
) -> Result<HttpResponse, ApiError> {
    let resp = service.user_get_notification_preferences(&session).await?;
    Ok(ApiResponse::ok(resp).to_response())
}

#[utoipa::path(
    patch,
    path = "/api/users/me/notifications/preferences",
    request_body = service::user::notification::NotificationPreferencesParams,
    responses(
        (status = 200, description = "Update notification preferences", body = ApiResponse<service::user::notification::NotificationPreferencesResponse>),
        (status = 401, description = "Unauthorized"),
),
    tag = "User"
)]
pub async fn update_notification_preferences(
    service: web::Data<AppService>,
    session: Session,
    body: web::Json<service::user::notification::NotificationPreferencesParams>,
) -> Result<HttpResponse, ApiError> {
    let resp = service
        .user_update_notification_preferences(&session, body.into_inner())
        .await?;
    Ok(ApiResponse::ok(resp).to_response())
}
