from django.urls import path

from nautobot.core.views.routers import NautobotUIViewSetRouter
from nautobot.extras.views import ObjectChangeLogView, ObjectDynamicGroupsView, ObjectNotesView

from . import views
from .models import (
    IPAddress,
)

app_name = "ipam"

router = NautobotUIViewSetRouter()
router.register("ip-address-to-interface", views.IPAddressToInterfaceUIViewSet)
router.register("namespaces", views.NamespaceUIViewSet)
router.register("prefixes", views.PrefixUIViewSet)
router.register("rirs", views.RIRUIViewSet)
router.register("route-targets", views.RouteTargetUIViewSet)
router.register("services", views.ServiceUIViewSet)
router.register("vlans", views.VLANUIViewSet)
router.register("vlan-groups", views.VLANGroupUIViewSet)
router.register("vrfs", views.VRFUIViewSet)

urlpatterns = [
    # IP addresses
    path("ip-addresses/", views.IPAddressListView.as_view(), name="ipaddress_list"),
    path("ip-addresses/add/", views.IPAddressEditView.as_view(), name="ipaddress_add"),
    path(
        "ip-addresses/bulk-add/",
        views.IPAddressBulkCreateView.as_view(),
        name="ipaddress_bulk_add",
    ),
    path(
        "ip-addresses/import/",
        views.IPAddressBulkImportView.as_view(),  # 3.0 TODO: remove, unused
        name="ipaddress_import",
    ),
    path(
        "ip-addresses/edit/",
        views.IPAddressBulkEditView.as_view(),
        name="ipaddress_bulk_edit",
    ),
    path(
        "ip-addresses/merge/",
        views.IPAddressMergeView.as_view(),
        name="ipaddress_merge",
    ),
    path(
        "ip-addresses/delete/",
        views.IPAddressBulkDeleteView.as_view(),
        name="ipaddress_bulk_delete",
    ),
    path(
        "ip-addresses/<uuid:pk>/changelog/",
        ObjectChangeLogView.as_view(),
        name="ipaddress_changelog",
        kwargs={"model": IPAddress},
    ),
    path(  # 3.0 TODO: remove, no longer needed/used since 2.3
        "ip-addresses/<uuid:pk>/dynamic-groups/",
        ObjectDynamicGroupsView.as_view(),
        name="ipaddress_dynamicgroups",
        kwargs={"model": IPAddress},
    ),
    path(
        "ip-addresses/<uuid:pk>/interfaces/",
        views.IPAddressInterfacesView.as_view(),
        name="ipaddress_interfaces",
    ),
    path(
        "ip-addresses/<uuid:pk>/vm-interfaces/",
        views.IPAddressVMInterfacesView.as_view(),
        name="ipaddress_vm_interfaces",
    ),
    path(
        "ip-addresses/<uuid:pk>/notes/",
        ObjectNotesView.as_view(),
        name="ipaddress_notes",
        kwargs={"model": IPAddress},
    ),
    path(
        "ip-addresses/assign/",
        views.IPAddressAssignView.as_view(),
        name="ipaddress_assign",
    ),
    path("ip-addresses/<uuid:pk>/", views.IPAddressView.as_view(), name="ipaddress"),
    path(
        "ip-addresses/<uuid:pk>/edit/",
        views.IPAddressEditView.as_view(),
        name="ipaddress_edit",
    ),
    path(
        "ip-addresses/<uuid:pk>/delete/",
        views.IPAddressDeleteView.as_view(),
        name="ipaddress_delete",
    ),
]

urlpatterns += router.urls
