# -*- coding: utf-8 -*-
from __future__ import annotations

from bthlabs_jsonrpc_django import is_authenticated
from django.urls import path

from hotpocket_backend.apps.core.rpc import JSONRPCView
from hotpocket_backend.apps.ui.constants import StarUnstarAssociationViewMode

# isort: off
from .views import (
    accounts,
    associations,
    imports,
    index,
    integrations,
    meta,
    saves,
)
# isort: on

urlpatterns = [
    path(
        'accounts/login/',
        accounts.auth.LoginView.as_view(),
        name='ui.accounts.login',
    ),
    path(
        'accounts/post-login/',
        accounts.auth.PostLoginView.as_view(),
        name='ui.accounts.post_login',
    ),
    path('accounts/logout/', accounts.auth.logout, name='ui.accounts.logout'),
    path('accounts/browse/', accounts.browse.browse, name='ui.accounts.browse'),
    path('accounts/settings/', accounts.settings.settings, name='ui.accounts.settings'),
    path(
        'accounts/settings/profile/',
        accounts.settings.ProfileView.as_view(),
        name='ui.accounts.settings.profile',
    ),
    path(
        'accounts/settings/password/',
        accounts.settings.PasswordView.as_view(),
        name='ui.accounts.settings.password',
    ),
    path(
        'accounts/settings/settings/',
        accounts.settings.SettingsView.as_view(),
        name='ui.accounts.settings.settings',
    ),
    path('accounts/apps/', accounts.apps.index, name='ui.accounts.apps.index'),
    path(
        'accounts/apps/browse/',
        accounts.apps.browse,
        name='ui.accounts.apps.browse',
    ),
    path(
        'accounts/apps/delete/<str:pk>',
        accounts.apps.DeleteView.as_view(),
        name='ui.accounts.apps.delete',
    ),
    path(
        'accounts/rpc/',
        JSONRPCView.as_view(
            namespace='accounts',
        ),
        name='ui.accounts.rpc',
    ),
    path('accounts/', accounts.index.index, name='ui.accounts.index'),
    path(
        'imports/pocket/',
        imports.PocketImportView.as_view(),
        name='ui.imports.pocket',
    ),
    path(
        'integrations/ios/shortcut/',
        integrations.ios.shortcut,
        name='ui.integrations.ios.shortcut',
    ),
    path(
        # Turns out PWAs can register a share target in Windows 11 when
        # installed through Edge. Neat, too. I wish I knew this when I defined
        # this URL path. Now it's gonna stay forever like this due to backwards
        # compat ;).
        'integrations/android/share-sheet/',
        integrations.pwa.share_sheet,
        name='ui.integrations.pwa.share_sheet',
    ),
    path(
        'integrations/extension/authenticate/',
        integrations.extension.authenticate,
        name='ui.integrations.extension.authenticate',
    ),
    path(
        'integrations/extension/post-authenticate/',
        integrations.extension.post_authenticate,
        name='ui.integrations.extension.post_authenticate',
    ),
    path(
        'saves/create/',
        saves.CreateView.as_view(),
        name='ui.saves.create',
    ),
    path('saves/embed/', saves.embed, name='ui.saves.embed'),
    path('associations/browse/', associations.browse, name='ui.associations.browse'),
    path('associations/view/<str:pk>/', associations.view, name='ui.associations.view'),
    path(
        'associations/edit/<str:pk>/',
        associations.EditView.as_view(),
        name='ui.associations.edit',
    ),
    path(
        'associations/star/<str:pk>/',
        associations.StarUnstarView.as_view(mode=StarUnstarAssociationViewMode.STAR),
        name='ui.associations.star',
    ),
    path(
        'associations/unstar/<str:pk>/',
        associations.StarUnstarView.as_view(mode=StarUnstarAssociationViewMode.UNSTAR),
        name='ui.associations.unstar',
    ),
    path(
        'associations/post-save/<str:pk>/',
        associations.post_save,
        name='ui.associations.post_save',
    ),
    path(
        'associations/refresh/<str:pk>/',
        associations.RefreshView.as_view(),
        name='ui.associations.refresh',
    ),
    path(
        'associations/archive/<str:pk>/',
        associations.ArchiveView.as_view(),
        name='ui.associations.archive',
    ),
    path(
        'associations/delete/<str:pk>/',
        associations.DeleteView.as_view(),
        name='ui.associations.delete',
    ),
    path('associations/', associations.index, name='ui.associations.index'),
    path('manifest.json', meta.manifest_json, name='ui.meta.manifest_json'),
    path(
        'rpc/',
        JSONRPCView.as_view(
            auth_checks=[is_authenticated],
        ),
        name='ui.rpc',
    ),
    path('', index.index, name='ui.index.index'),
]
