"""Advanced metrics endpoints — coverage by tactic, never-tested, avg validation time."""

# Import APIRouter, Depends from fastapi
from fastapi import APIRouter, Depends

# Import Session from sqlalchemy.orm
from sqlalchemy.orm import Session

# Import get_db from app.database
from app.database import get_db

# Import get_current_user from app.dependencies.auth
from app.dependencies.auth import get_current_user

# Import User from app.models.user
from app.models.user import User

# Import advanced_metrics_service from app.services
from app.services import advanced_metrics_service

# Assign router = APIRouter(prefix="/metrics/advanced", tags=["advanced-metrics"])
router = APIRouter(prefix="/metrics/advanced", tags=["advanced-metrics"])


# Apply the @router.get decorator
@router.get("/coverage-by-tactic")
# Define function coverage_by_tactic
def coverage_by_tactic(
    # Entry: db
    db: Session = Depends(get_db),
    # Entry: user
    user: User = Depends(get_current_user),
) -> list:
    """Coverage percentage broken down by MITRE ATT&CK tactic."""
    # Return advanced_metrics_service.get_coverage_by_tactic(db)
    return advanced_metrics_service.get_coverage_by_tactic(db)


# Apply the @router.get decorator
@router.get("/never-tested")
# Define function never_tested_techniques
def never_tested_techniques(
    # Entry: db
    db: Session = Depends(get_db),
    # Entry: user
    user: User = Depends(get_current_user),
) -> list:
    """Techniques that have never had a test created."""
    # Return advanced_metrics_service.get_never_tested_techniques(db)
    return advanced_metrics_service.get_never_tested_techniques(db)


# Apply the @router.get decorator
@router.get("/avg-validation-time")
# Define function avg_validation_time
def avg_validation_time(
    # Entry: db
    db: Session = Depends(get_db),
    # Entry: user
    user: User = Depends(get_current_user),
) -> dict:
    """Average time from test creation to validation, computed from audit logs.

    Returns overall average and per-phase averages where data is available.
    """
    # Return advanced_metrics_service.get_avg_validation_time(db)
    return advanced_metrics_service.get_avg_validation_time(db)


# Apply the @router.get decorator
@router.get("/detection-rate-trend")
# Define function detection_rate_trend
def detection_rate_trend(
    # Entry: db
    db: Session = Depends(get_db),
    # Entry: user
    user: User = Depends(get_current_user),
) -> list:
    """Monthly detection rate trend for the last 12 months."""
    # Return advanced_metrics_service.get_detection_rate_trend(db)
    return advanced_metrics_service.get_detection_rate_trend(db)
