from django.conf import settings
from django.conf.urls import url
from django.contrib import admin
from django.urls import include, path
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions

# for non API errors render json instead of default HTML
handler500 = "rest_framework.exceptions.server_error"
handler400 = "rest_framework.exceptions.bad_request"

# custom view can be created with the right status code and detail
handler404 = "rest_framework.exceptions.bad_request"


urlpatterns = [
    path("admin/", admin.site.urls),
    path(r"movies/", include(("movies.urls", "movies"), namespace="movies")),
]

if "debug_toolbar" in settings.INSTALLED_APPS:
    import debug_toolbar

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


if settings.EXPOSE_SWAGGER_INTERFACE:
    schema_view = get_schema_view(
        openapi.Info(
            title="Totoro API",
            default_version="v1",
            description="Totoro Application API",
        ),
        public=True,
        permission_classes=(permissions.AllowAny,),
    )

    urlpatterns += [
        url(r"^$", schema_view.with_ui("swagger"), name="schema-swagger-ui",),
        url(r"^redoc/$", schema_view.with_ui("redoc"), name="schema-redoc",),
    ]
