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

from newsreader.news.core.endpoints import (
    CategoryReadView,
    DetailCategoryView,
    DetailPostView,
    ListCategoryView,
    ListPostView,
    NestedPostCategoryView,
    NestedRuleCategoryView,
)
from newsreader.news.core.views import (
    CategoryCreateView,
    CategoryListView,
    CategoryUpdateView,
)


urlpatterns = [
    path("categories/", login_required(CategoryListView.as_view()), name="categories"),
    path(
        "categories/<int:pk>/",
        login_required(CategoryUpdateView.as_view()),
        name="category-update",
    ),
    path(
        "categories/create/",
        login_required(CategoryCreateView.as_view()),
        name="category-create",
    ),
]

endpoints = [
    path("posts/", ListPostView.as_view(), name="posts-list"),
    path("posts/<int:pk>/", DetailPostView.as_view(), name="posts-detail"),
    path("categories/", ListCategoryView.as_view(), name="categories-list"),
    path(
        "categories/<int:pk>/", DetailCategoryView.as_view(), name="categories-detail"
    ),
    path(
        "categories/<int:pk>/read/", CategoryReadView.as_view(), name="categories-read"
    ),
    path(
        "categories/<int:pk>/rules/",
        NestedRuleCategoryView.as_view(),
        name="categories-nested-rules",
    ),
    path(
        "categories/<int:pk>/posts/",
        NestedPostCategoryView.as_view(),
        name="categories-nested-posts",
    ),
]
