# Copyright (c) 2023-present Plane Software, Inc. and contributors
# SPDX-License-Identifier: AGPL-3.0-only
# See the LICENSE file for details.

"""plane URL Configuration"""

from django.conf import settings
from django.urls import include, path, re_path
from drf_spectacular.views import (
    SpectacularAPIView,
    SpectacularRedocView,
    SpectacularSwaggerView,
)
from plane.authentication.views.nodedc_logout import (
    NodeDCFrontChannelLogoutEndpoint,
    NodeDCInternalSessionLogoutEndpoint,
)
from plane.authentication.views.nodedc_agent_adapter import (
    NodeDCAgentIssueAssigneesEndpoint,
    NodeDCAgentIssueAttachmentEndpoint,
    NodeDCAgentIssueCommentEndpoint,
    NodeDCAgentIssueLabelsEndpoint,
    NodeDCAgentIssueListEndpoint,
    NodeDCAgentIssueMoveEndpoint,
    NodeDCAgentIssueUpdateEndpoint,
    NodeDCAgentProjectContextEndpoint,
    NodeDCAgentProjectCreateEndpoint,
    NodeDCAgentProjectLabelsEnsureEndpoint,
    NodeDCAgentProjectResolveEndpoint,
)
from plane.authentication.views.nodedc_workspace_adapter import (
    NodeDCInternalProjectMembershipEnsureEndpoint,
    NodeDCInternalProjectMembershipRemoveEndpoint,
    NodeDCInternalUserProfileSyncEndpoint,
    NodeDCInternalWorkspaceInviteApproveEndpoint,
    NodeDCInternalWorkspaceInviteRejectEndpoint,
    NodeDCInternalWorkspaceListEndpoint,
    NodeDCInternalWorkspaceMembershipEnsureEndpoint,
    NodeDCInternalWorkspaceMembershipRemoveEndpoint,
)

handler404 = "plane.app.views.error_404.custom_404_view"

urlpatterns = [
    path(
        "api/internal/nodedc/logout/",
        NodeDCInternalSessionLogoutEndpoint.as_view(),
        name="nodedc-internal-session-logout",
    ),
    path(
        "api/internal/nodedc/workspaces/",
        NodeDCInternalWorkspaceListEndpoint.as_view(),
        name="nodedc-internal-workspaces",
    ),
    path(
        "api/internal/nodedc/users/profile-sync/",
        NodeDCInternalUserProfileSyncEndpoint.as_view(),
        name="nodedc-internal-user-profile-sync",
    ),
    path(
        "api/internal/nodedc/workspace-memberships/ensure/",
        NodeDCInternalWorkspaceMembershipEnsureEndpoint.as_view(),
        name="nodedc-internal-workspace-membership-ensure",
    ),
    path(
        "api/internal/nodedc/workspace-memberships/remove/",
        NodeDCInternalWorkspaceMembershipRemoveEndpoint.as_view(),
        name="nodedc-internal-workspace-membership-remove",
    ),
    path(
        "api/internal/nodedc/workspace-invite-requests/approve/",
        NodeDCInternalWorkspaceInviteApproveEndpoint.as_view(),
        name="nodedc-internal-workspace-invite-approve",
    ),
    path(
        "api/internal/nodedc/workspace-invite-requests/reject/",
        NodeDCInternalWorkspaceInviteRejectEndpoint.as_view(),
        name="nodedc-internal-workspace-invite-reject",
    ),
    path(
        "api/internal/nodedc/project-memberships/ensure/",
        NodeDCInternalProjectMembershipEnsureEndpoint.as_view(),
        name="nodedc-internal-project-membership-ensure",
    ),
    path(
        "api/internal/nodedc/project-memberships/remove/",
        NodeDCInternalProjectMembershipRemoveEndpoint.as_view(),
        name="nodedc-internal-project-membership-remove",
    ),
    path(
        "api/internal/nodedc/agent/projects/resolve",
        NodeDCAgentProjectResolveEndpoint.as_view(),
        name="nodedc-agent-project-resolve",
    ),
    path(
        "api/internal/nodedc/agent/projects",
        NodeDCAgentProjectCreateEndpoint.as_view(),
        name="nodedc-agent-project-create",
    ),
    path(
        "api/internal/nodedc/agent/projects/<uuid:project_id>/context",
        NodeDCAgentProjectContextEndpoint.as_view(),
        name="nodedc-agent-project-context",
    ),
    path(
        "api/internal/nodedc/agent/projects/<uuid:project_id>/labels/ensure",
        NodeDCAgentProjectLabelsEnsureEndpoint.as_view(),
        name="nodedc-agent-project-labels-ensure",
    ),
    path(
        "api/internal/nodedc/agent/issues",
        NodeDCAgentIssueListEndpoint.as_view(),
        name="nodedc-agent-issue-list",
    ),
    path(
        "api/internal/nodedc/agent/issues/<uuid:issue_id>",
        NodeDCAgentIssueUpdateEndpoint.as_view(),
        name="nodedc-agent-issue-update",
    ),
    path(
        "api/internal/nodedc/agent/issues/<uuid:issue_id>/move",
        NodeDCAgentIssueMoveEndpoint.as_view(),
        name="nodedc-agent-issue-move",
    ),
    path(
        "api/internal/nodedc/agent/issues/<uuid:issue_id>/comments",
        NodeDCAgentIssueCommentEndpoint.as_view(),
        name="nodedc-agent-issue-comment",
    ),
    path(
        "api/internal/nodedc/agent/issues/<uuid:issue_id>/attachments",
        NodeDCAgentIssueAttachmentEndpoint.as_view(),
        name="nodedc-agent-issue-attachment",
    ),
    path(
        "api/internal/nodedc/agent/issues/<uuid:issue_id>/labels",
        NodeDCAgentIssueLabelsEndpoint.as_view(),
        name="nodedc-agent-issue-labels",
    ),
    path(
        "api/internal/nodedc/agent/issues/<uuid:issue_id>/assignees",
        NodeDCAgentIssueAssigneesEndpoint.as_view(),
        name="nodedc-agent-issue-assignees",
    ),
    path("api/", include("plane.app.urls")),
    path("api/public/", include("plane.space.urls")),
    path("api/instances/", include("plane.license.urls")),
    path("api/v1/", include("plane.api.urls")),
    path("auth/", include("plane.authentication.urls")),
    path(
        "logout",
        NodeDCFrontChannelLogoutEndpoint.as_view(),
        name="nodedc-frontchannel-logout",
    ),
    path("", include("plane.web.urls")),
]

if settings.ENABLE_DRF_SPECTACULAR:
    urlpatterns += [
        path("api/schema/", SpectacularAPIView.as_view(), name="schema"),
        path(
            "api/schema/swagger-ui/",
            SpectacularSwaggerView.as_view(url_name="schema"),
            name="swagger-ui",
        ),
        path(
            "api/schema/redoc/",
            SpectacularRedocView.as_view(url_name="schema"),
            name="redoc",
        ),
    ]

if settings.DEBUG:
    try:
        import debug_toolbar

        urlpatterns = [re_path(r"^__debug__/", include(debug_toolbar.urls))] + urlpatterns
    except ImportError:
        pass
