use actix_web::{HttpResponse, web};
use service::{
    AppService,
    auth::reset_pass::{ResetPasswordRequest, ResetPasswordVerifyParams},
};
use session::Session;

use crate::error::ApiError;

fn ok() -> Result<HttpResponse, ApiError> {
    Ok(HttpResponse::Ok().finish())
}

#[utoipa::path(
    post,
    path = "/api/v1/auth/reset-password/request",
    request_body = ResetPasswordRequest,
    responses((status = 200)),
    tag = "auth"
)]
pub async fn reset_password_request(
    params: web::Json<ResetPasswordRequest>,
    service: web::Data<AppService>,
) -> Result<HttpResponse, ApiError> {
    service
        .auth_reset_password_request(params.into_inner())
        .await?;
    ok()
}

#[utoipa::path(
    post,
    path = "/api/v1/auth/reset-password/verify",
    request_body = ResetPasswordVerifyParams,
    responses((status = 200)),
    tag = "auth"
)]
pub async fn reset_password_verify(
    session: Session,
    params: web::Json<ResetPasswordVerifyParams>,
    service: web::Data<AppService>,
) -> Result<HttpResponse, ApiError> {
    service
        .auth_reset_password_verify(&session, params.into_inner())
        .await?;
    ok()
}
