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

#[utoipa::path(
    post,
    path = "/api/auth/login",
    request_body = LoginParams,
    responses(
        (status = 200, description = "Login successful", body = ApiResponse<String>),
        (status = 401, description = "Invalid credentials", body = ApiResponse<ApiError>),
        (status = 428, description = "Two-factor authentication required", body = ApiResponse<ApiError>),
        (status = 400, description = "Bad request", body = ApiResponse<ApiError>),
        (status = 404, description = "Not found", body = ApiResponse<ApiError>),
    ),
    tag = "Auth"
)]
pub async fn api_auth_login(
    service: web::Data<AppService>,
    session: Session,
    params: web::Json<LoginParams>,
) -> Result<HttpResponse, ApiError> {
    service.auth_login(params.into_inner(), session).await?;
    Ok(crate::api_success())
}
