from rest_framework import routers

from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin, flatpages
from django.contrib.sitemaps.views import sitemap
from django.urls import include, path, re_path
from django.views.generic import RedirectView

from posts.viewsets import PostViewSet
from members.urls import jobs_urlpatterns, member_urlpatterns
from members.viewsets import (
    MemberViewSet,
    JobViewSet,
    JobGroupViewSet,
    JobMemberViewSet,
)
from . import views
from .sitemaps import sitemaps


router = routers.DefaultRouter()
router.register(r"posts", PostViewSet)
router.register(r"members", MemberViewSet)
router.register(r"jobgroups", JobGroupViewSet)
router.register(r"jobs", JobViewSet)
router.register(r"jobmembers", JobMemberViewSet)

urlpatterns = [
    path("admin/doc/", include("django.contrib.admindocs.urls")),
    path("admin/login/", RedirectView.as_view(pattern_name="login")),
    path("admin/", admin.site.urls),
    path("auth/", include("authentications.urls")),
    path("", views.index, name="home"),
    path("api/", include(router.urls)),
    path("blackboard/", include("blackboard.urls"), name="blackboard"),
    path("ckeditor/", include("ckeditor_uploader.urls")),
    path("gallery/", include("gallery.urls"), name="gallery"),
    path("index.html", views.index, name="home"),
    path("jobs/", include(jobs_urlpatterns), name="jobs"),
    path("members/", include("members.urls"), name="members"),
    path("member/", include(member_urlpatterns), name="member"),
    path("posts/", include("posts.urls")),
    path("tasks/", include("tasks.urls"), name="tasks"),
    path(
        "discord/",
        RedirectView.as_view(url="https://discord.com/invite/7qRuuMA"),
        name="discord",
    ),
    path(
        "facebook/",
        RedirectView.as_view(url="https://www.facebook.com/FachschaftET/"),
        name="facebook",
    ),
    path(
        "instagram/",
        RedirectView.as_view(url="https://www.instagram.com/fet_tuwien/"),
        name="instagram",
    ),
    path(
        "telegram/", RedirectView.as_view(url="https://t.me/FETInfo"), name="telegram"
    ),
    path(
        "sitemap.xml",
        sitemap,
        {"sitemaps": sitemaps},
        name="django.contrib.sitemaps.views.sitemap",
    ),
    path("pages/", include("django.contrib.flatpages.urls")),
    re_path(r"^(?P<url>.*/)$", flatpages.views.flatpage),
    path(
        "impressum/", flatpages.views.flatpage, {"url": "/impressum/"}, name="impressum"
    ),
    path("kontakt/", flatpages.views.flatpage, {"url": "/kontakt/"}, name="contact"),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
