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

#[utoipa::path(
    get,
    path = "/api/workspaces/{slug}/stats",
    params(
        ("slug" = String, Path, description = "Workspace slug")
    ),
    responses(
        (status = 200, description = "Get workspace stats", body = ApiResponse<WorkspaceStatsResponse>),
        (status = 401, description = "Unauthorized"),
        (status = 403, description = "Not a workspace member"),
        (status = 404, description = "Workspace not found"),
    ),
    tag = "Workspace"
)]
pub async fn workspace_stats(
    service: web::Data<AppService>,
    session: Session,
    path: web::Path<String>,
) -> Result<HttpResponse, ApiError> {
    let slug = path.into_inner();
    let resp = service.workspace_stats(&session, slug).await?;
    Ok(ApiResponse::ok(resp).to_response())
}
