"""
URL configuration for ThrillWiki API v1.

This module provides unified API routing following RESTful conventions
and DRF Router patterns for automatic URL generation.
"""

from django.urls import include, path
from rest_framework.routers import DefaultRouter

# Import other views from the views directory
from .views import (
    CoasterStatisticsAPIView,
    DataCompletenessAPIView,
    HealthCheckAPIView,
    NewContentAPIView,
    PerformanceMetricsAPIView,
    SimpleHealthAPIView,
    TechnicalSpecificationsAPIView,
    # Trending system views
    TrendingAPIView,
    TriggerTrendingCalculationAPIView,
)
from .views.discovery import DiscoveryAPIView
from .views.leaderboard import leaderboard
from .views.reviews import LatestReviewsAPIView
from .views.stats import StatsAPIView, StatsRecalculateAPIView
from .viewsets_rankings import RideRankingViewSet, TriggerRankingCalculationView

# Import analytics views
from apps.core.api.analytics_views import (
    ApprovalTransactionMetricViewSet,
    ErrorSummaryView,
    RequestMetadataViewSet,
)

# Create the main API router
router = DefaultRouter()

# Register ranking endpoints
router.register(r"rankings", RideRankingViewSet, basename="ranking")

# Register analytics endpoints
router.register(r"request_metadata", RequestMetadataViewSet, basename="request_metadata")
router.register(r"approval_transaction_metrics", ApprovalTransactionMetricViewSet, basename="approval_transaction_metrics")

app_name = "api_v1"

urlpatterns = [
    # API Documentation endpoints are handled by main Django URLs
    # See backend/thrillwiki/urls.py for documentation endpoints
    # Authentication endpoints
    path("auth/", include("apps.api.v1.auth.urls")),
    # Analytics endpoints (error_summary is a view, not a viewset)
    path("error_summary/", ErrorSummaryView.as_view(), name="error-summary"),
    # Health check endpoints
    path("health/", HealthCheckAPIView.as_view(), name="health-check"),
    path("health/simple/", SimpleHealthAPIView.as_view(), name="simple-health"),
    path(
        "health/performance/",
        PerformanceMetricsAPIView.as_view(),
        name="performance-metrics",
    ),
    # Trending system endpoints
    path("trending/", TrendingAPIView.as_view(), name="trending"),
    path("discovery/", DiscoveryAPIView.as_view(), name="discovery"),
    path("new-content/", NewContentAPIView.as_view(), name="new-content"),
    path(
        "trending/calculate/",
        TriggerTrendingCalculationAPIView.as_view(),
        name="trigger-trending-calculation",
    ),
    # Statistics endpoints
    path("stats/", StatsAPIView.as_view(), name="stats"),
    path(
        "stats/recalculate/",
        StatsRecalculateAPIView.as_view(),
        name="stats-recalculate",
    ),
    # Reviews endpoints
    path("reviews/latest/", LatestReviewsAPIView.as_view(), name="latest-reviews"),
    # Leaderboard endpoint
    path("leaderboard/", leaderboard, name="leaderboard"),
    # Ranking system endpoints
    path(
        "rankings/calculate/",
        TriggerRankingCalculationView.as_view(),
        name="trigger-ranking-calculation",
    ),
    # Admin endpoints
    path(
        "admin/data-completeness/",
        DataCompletenessAPIView.as_view(),
        name="data-completeness",
    ),
    # Ride search advanced endpoints (for useAdvancedRideSearch composable)
    path(
        "rides/technical-specifications/",
        TechnicalSpecificationsAPIView.as_view(),
        name="technical-specifications",
    ),
    path(
        "rides/coaster-statistics/",
        CoasterStatisticsAPIView.as_view(),
        name="coaster-statistics",
    ),
    # Domain-specific API endpoints
    path("parks/", include("apps.api.v1.parks.urls")),
    path("rides/", include("apps.api.v1.rides.urls")),
    path("accounts/", include("apps.api.v1.accounts.urls")),
    path("history/", include("apps.api.v1.history.urls")),
    path("email/", include("apps.api.v1.email.urls")),
    path("core/", include("apps.api.v1.core.urls")),
    path("maps/", include("apps.api.v1.maps.urls")),
    path("lists/", include("apps.lists.urls")),
    path("companies/", include("apps.api.v1.rides.company_urls")),
    path("moderation/", include("apps.moderation.urls")),
    path("reviews/", include("apps.reviews.urls")),
    path("media/", include("apps.media.urls")),
    path("blog/", include("apps.blog.urls")),
    path("support/", include("apps.support.urls")),
    path("notifications/", include("apps.notifications.urls")),
    path("errors/", include("apps.core.urls.errors")),
    path("images/", include("apps.api.v1.images.urls")),
    # Admin dashboard API endpoints
    path("admin/", include("apps.api.v1.admin.urls")),
    # Cloudflare Images Toolkit API endpoints
    path("cloudflare-images/", include("django_cloudflareimages_toolkit.urls")),
    # Include router URLs (for rankings and any other router-registered endpoints)
    path("", include(router.urls)),
]

