from django.urls import include, path, register_converter
from django.utils.translation import gettext_lazy as _
from rest_framework.routers import DefaultRouter

from . import models, views, viewsets
from .converters import DateConverter, PagePathConverter, WeekConverter

__all__ = ["api", "urls"]


register_converter(PagePathConverter, "page_path")
register_converter(DateConverter, "date")
register_converter(WeekConverter, "week")


# urls = [
#    path('on_air', views.on_air, name='aircox.on_air'),
#    path('monitor', views.Monitor.as_view(), name='aircox.monitor'),
#    path('stats', views.StatisticsView.as_view(), name='aircox.stats'),
# ]


router = DefaultRouter()
router.register("sound", viewsets.SoundViewSet, basename="sound")
router.register("track", viewsets.TrackROViewSet, basename="track")


api = [
    path("logs/", views.LogListAPIView.as_view(), name="live"),
    path(
        "user/settings/",
        viewsets.UserSettingsViewSet.as_view({"get": "retrieve", "post": "update", "put": "update"}),
        name="user-settings",
    ),
] + router.urls


urls = [
    path("", views.HomeView.as_view(), name="home"),
    path("api/", include((api, "aircox"), namespace="api")),
    # path('', views.PageDetailView.as_view(model=models.Article),
    #     name='home'),
    path(
        _("articles/"),
        views.ArticleListView.as_view(model=models.Article),
        name="article-list",
    ),
    path(
        _("articles/<slug:slug>/"),
        views.ArticleDetailView.as_view(),
        name="article-detail",
    ),
    path(_("episodes/"), views.EpisodeListView.as_view(), name="episode-list"),
    path(
        _("episodes/<slug:slug>/"),
        views.EpisodeDetailView.as_view(),
        name="episode-detail",
    ),
    path(_("week/"), views.DiffusionListView.as_view(), name="diffusion-list"),
    path(
        _("week/<date:date>/"),
        views.DiffusionListView.as_view(),
        name="diffusion-list",
    ),
    path(_("logs/"), views.LogListView.as_view(), name="log-list"),
    path(_("logs/<date:date>/"), views.LogListView.as_view(), name="log-list"),
    # path('<page_path:path>', views.route_page, name='page'),
    path(
        _("publications/"),
        views.PageListView.as_view(model=models.Page),
        name="page-list",
    ),
    path(
        _("pages/"),
        views.BasePageListView.as_view(
            model=models.StaticPage,
            queryset=models.StaticPage.objects.filter(attach_to__isnull=True),
        ),
        name="static-page-list",
    ),
    path(
        _("pages/<slug:slug>/"),
        views.BasePageDetailView.as_view(
            model=models.StaticPage,
            queryset=models.StaticPage.objects.filter(attach_to__isnull=True),
        ),
        name="static-page-detail",
    ),
    path(_("programs/"), views.ProgramListView.as_view(), name="program-list"),
    path(
        _("programs/<slug:slug>/"),
        views.ProgramDetailView.as_view(),
        name="program-detail",
    ),
    path(
        _("program/<pk>/edit/"),
        views.ProgramUpdateView.as_view(),
        name="program-edit",
    ),
    path(
        _("programs/<slug:parent_slug>/episodes/"),
        views.EpisodeListView.as_view(),
        name="episode-list",
    ),
    path(
        _("programs/<slug:parent_slug>/articles/"),
        views.ArticleListView.as_view(),
        name="article-list",
    ),
    path(
        _("programs/<slug:parent_slug>/publications/"),
        views.ProgramPageListView.as_view(),
        name="program-page-list",
    ),
    path(
        "errors/no-station",
        views.errors.NoStationErrorView.as_view(),
        name="errors-no-station",
    ),
    path("gestion/", views.profile, name="profile"),
    path("accounts/profile/", views.profile, name="profile"),
]
