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

from newsreader.accounts.views import (
    ActivationCompleteView,
    ActivationResendView,
    ActivationView,
    FaviconRedirectView,
    IntegrationsView,
    LoginView,
    LogoutView,
    PasswordChangeView,
    PasswordResetCompleteView,
    PasswordResetConfirmView,
    PasswordResetDoneView,
    PasswordResetView,
    RedditRevokeRedirectView,
    RedditTemplateView,
    RedditTokenRedirectView,
    RegistrationClosedView,
    RegistrationCompleteView,
    RegistrationView,
    SettingsView,
    TwitterAuthRedirectView,
    TwitterRevokeRedirectView,
    TwitterTemplateView,
)


settings_patterns = [
    # Integrations
    path(
        "integrations/reddit/callback/",
        login_required(RedditTemplateView.as_view()),
        name="reddit-template",
    ),
    path(
        "integrations/reddit/refresh/",
        login_required(RedditTokenRedirectView.as_view()),
        name="reddit-refresh",
    ),
    path(
        "integrations/reddit/revoke/",
        login_required(RedditRevokeRedirectView.as_view()),
        name="reddit-revoke",
    ),
    path(
        "integrations/twitter/auth/",
        login_required(TwitterAuthRedirectView.as_view()),
        name="twitter-auth",
    ),
    path(
        "integrations/twitter/callback/",
        login_required(TwitterTemplateView.as_view()),
        name="twitter-template",
    ),
    path(
        "integrations/twitter/revoke/",
        login_required(TwitterRevokeRedirectView.as_view()),
        name="twitter-revoke",
    ),
    path(
        "integrations/", login_required(IntegrationsView.as_view()), name="integrations"
    ),
    # Misc
    path("favicon/", login_required(FaviconRedirectView.as_view()), name="favicon"),
    path("", login_required(SettingsView.as_view()), name="home"),
]

urlpatterns = [
    # Auth
    path("login/", LoginView.as_view(), name="login"),
    path("logout/", LogoutView.as_view(), name="logout"),
    # Register
    path("register/", RegistrationView.as_view(), name="register"),
    path(
        "register/complete/",
        RegistrationCompleteView.as_view(),
        name="register-complete",
    ),
    path("register/closed/", RegistrationClosedView.as_view(), name="register-closed"),
    path(
        "activate/complete/", ActivationCompleteView.as_view(), name="activate-complete"
    ),
    path("activate/resend/", ActivationResendView.as_view(), name="activate-resend"),
    path(
        # This URL should be placed after all activate/ url's (see arg)
        "activate/<str:activation_key>/",
        ActivationView.as_view(),
        name="activate",
    ),
    # Password
    path("password-reset/", PasswordResetView.as_view(), name="password-reset"),
    path(
        "password-reset/done/",
        PasswordResetDoneView.as_view(),
        name="password-reset-done",
    ),
    path(
        "password-reset/<uidb64>/<token>/",
        PasswordResetConfirmView.as_view(),
        name="password-reset-confirm",
    ),
    path(
        "password-reset/done/",
        PasswordResetCompleteView.as_view(),
        name="password-reset-complete",
    ),
    path(
        "password-change/",
        login_required(PasswordChangeView.as_view()),
        name="password-change",
    ),
    # Settings
    path("settings/", include((settings_patterns, "settings"))),
]
