"""审计日志与统计只读 HTTP 接口。"""

from __future__ import annotations

from flask import request

from dms.api.v1.blueprint import api_v1
from dms.common.response import success_response
from dms.security.decorators import (
    admin_required,
    bearer_auth_required,
)
from dms.services.audit_query_service import (
    action_statistics,
    active_user_statistics,
    audit_log_page,
    document_statistics,
    trend_statistics,
)


@api_v1.get("/audit/logs")
@bearer_auth_required
@admin_required
def audit_logs_route():
    return success_response(audit_log_page(request.args))


@api_v1.get("/statistics/documents")
@bearer_auth_required
@admin_required
def document_statistics_route():
    return success_response(document_statistics(request.args))


@api_v1.get("/audit/statistics/trend")
@bearer_auth_required
@admin_required
def audit_trend_statistics_route():
    return success_response(trend_statistics(request.args))


@api_v1.get("/audit/statistics/actions")
@bearer_auth_required
@admin_required
def audit_action_statistics_route():
    return success_response(action_statistics(request.args))


@api_v1.get("/audit/statistics/users")
@bearer_auth_required
@admin_required
def audit_active_user_statistics_route():
    return success_response(active_user_statistics(request.args))
