from django.conf import settings
from django.contrib import admin
from django.urls import include, path, re_path
from django.views.generic.base import RedirectView
from rest_framework.routers import DefaultRouter

from .views import ArtistListView, HomeView, AlbumListView
from .viewsets import AlbumViewSet, ArtistViewSet, TrackViewSet

urlpatterns = [
    path("", HomeView.as_view(), name="home"),
    path("search", ArtistListView.as_view(), name="search"),
    path("artists", ArtistListView.as_view(), name="artist-list"),
    path("albums", AlbumListView.as_view(), name="album-list"),
]


if settings.DJANGO_ADMIN_ENABLED:
    urlpatterns += [
        path("admin/", admin.site.urls),
    ]

if settings.DJANGO_API_ENABLED:
    api_router = DefaultRouter(trailing_slash=False)
    api_router.register("artists", ArtistViewSet)
    api_router.register("albums", AlbumViewSet)
    api_router.register("tracks", TrackViewSet)

    urlpatterns += [
        path("api/<version>/", include(api_router.urls)),
    ]
