from django.conf import settings
from django.contrib import admin
from django.contrib.auth.decorators import login_required
from django.urls import include, path

from newsreader.accounts.urls import urlpatterns as login_urls
from newsreader.news.core.views import NewsView
from newsreader.news.urls import endpoints as news_endpoints
from newsreader.news.urls import urlpatterns as news_patterns


api_patterns = [path("api/", include((news_endpoints, "news")))]

urlpatterns = [
    path("", login_required(NewsView.as_view()), name="index"),
    path("", include((news_patterns, "news"))),
    path("", include((api_patterns, "api"))),
    path("accounts/", include((login_urls, "accounts")), name="accounts"),
    path("admin/", admin.site.urls, name="admin"),
    path("api/auth/", include("rest_framework.urls"), name="rest_framework"),
]

handler400 = "newsreader.core.views.bad_request"
handler403 = "newsreader.core.views.permission_denied"
handler404 = "newsreader.core.views.not_found"
handler500 = "newsreader.core.views.server_error"


if settings.DEBUG:
    import debug_toolbar

    urlpatterns = [path("debug/", include(debug_toolbar.urls))] + urlpatterns
