from django.urls import include, path

from .models import InterfaceTypeMapping
from .views import (
    AddDeviceToLibreNMSView,
    AssignVCSerialView,
    BulkImportConfirmView,
    BulkImportDevicesView,
    CreateAndAssignPlatformView,
    DeleteNetBoxInterfacesView,
    DeviceCableTableView,
    DeviceClusterUpdateView,
    DeviceConflictActionView,
    DeviceInterfaceTableView,
    DeviceIPAddressTableView,
    DeviceLibreNMSSyncView,
    DeviceRackUpdateView,
    DeviceRoleUpdateView,
    DeviceStatusListView,
    DeviceValidationDetailsView,
    DeviceVCDetailsView,
    DeviceVLANTableView,
    InterfaceTypeMappingBulkDeleteView,
    InterfaceTypeMappingBulkImportView,
    InterfaceTypeMappingChangeLogView,
    InterfaceTypeMappingCreateView,
    InterfaceTypeMappingDeleteView,
    InterfaceTypeMappingEditView,
    InterfaceTypeMappingListView,
    InterfaceTypeMappingView,
    LibreNMSImportView,
    LibreNMSSettingsView,
    RemoveServerMappingView,
    SaveUserPrefView,
    SingleCableVerifyView,
    SingleInterfaceVerifyView,
    SingleIPAddressVerifyView,
    SaveVlanGroupOverridesView,
    SingleVlanGroupVerifyView,
    VerifyVlanSyncGroupView,
    SyncCablesView,
    SyncInterfacesView,
    SyncIPAddressesView,
    SyncSiteLocationView,
    SyncVLANsView,
    TestLibreNMSConnectionView,
    UpdateDeviceLocationView,
    UpdateDeviceNameView,
    UpdateDevicePlatformView,
    UpdateDeviceSerialView,
    UpdateDeviceTypeView,
    VMInterfaceTableView,
    VMIPAddressTableView,
    VMLibreNMSSyncView,
    VMStatusListView,
    ConvertLegacyLibreNMSIdView,
)

urlpatterns = [
    # Device sync URLs
    path(
        "device/<int:pk>/librenms-sync/",
        DeviceLibreNMSSyncView.as_view(),
        name="device_librenms_sync",
    ),
    path(
        "devices/<int:pk>/interface-sync/",
        DeviceInterfaceTableView.as_view(),
        name="device_interface_sync",
    ),
    path(
        "devices/<int:pk>/cable-sync/",
        DeviceCableTableView.as_view(),
        name="device_cable_sync",
    ),
    path(
        "devices/<int:pk>/ipaddress-sync/",
        DeviceIPAddressTableView.as_view(),
        name="device_ipaddress_sync",
    ),
    # Path for single interface verify javascript call
    path(
        "verify-interface/",
        SingleInterfaceVerifyView.as_view(),
        name="verify_interface",
    ),
    path(
        "verify-cable/",
        SingleCableVerifyView.as_view(),
        name="verify_cable",
    ),
    # Path for single IP address verify javascript call
    path(
        "verify-ipaddress/",
        SingleIPAddressVerifyView.as_view(),
        name="verify_ipaddress",
    ),
    # Path for VLAN group verify javascript call (interface VLAN coloring)
    path(
        "verify-vlan-group/",
        SingleVlanGroupVerifyView.as_view(),
        name="verify_vlan_group",
    ),
    # Verify VLAN existence in a group (VLAN sync tab coloring)
    path(
        "verify-vlan-sync-group/",
        VerifyVlanSyncGroupView.as_view(),
        name="verify_vlan_sync_group",
    ),
    # Save VLAN group overrides to cache ("apply to all" persistence)
    path(
        "save-vlan-group-overrides/",
        SaveVlanGroupOverridesView.as_view(),
        name="save_vlan_group_overrides",
    ),
    # Virtual machine sync URLs
    path(
        "virtual-machines/<int:pk>/interface-sync/",
        VMInterfaceTableView.as_view(),
        name="vm_interface_sync",
    ),
    path(
        "virtual-machines/<int:pk>/ipaddress-sync/",
        VMIPAddressTableView.as_view(),
        name="vm_ipaddress_sync",
    ),
    path(
        "virtual-machines/<int:pk>/librenms-sync/",
        VMLibreNMSSyncView.as_view(),
        name="vm_librenms_sync",
    ),
    # Sync interfaces URL
    path(
        "<str:object_type>/<int:object_id>/sync-interfaces/",
        SyncInterfacesView.as_view(),
        name="sync_selected_interfaces",
    ),
    # Delete NetBox-only interfaces URL
    path(
        "<str:object_type>/<int:object_id>/delete-netbox-interfaces/",
        DeleteNetBoxInterfacesView.as_view(),
        name="delete_netbox_interfaces",
    ),
    # Sync cables URL
    path(
        "device/<int:pk>/sync-cables/",
        SyncCablesView.as_view(),
        name="sync_device_cables",
    ),
    # Sync IP addresses URL
    path(
        "<str:object_type>/<int:pk>/sync-ip-addresses/",
        SyncIPAddressesView.as_view(),
        name="sync_device_ip_addresses",
    ),
    # VLAN sync URLs
    path(
        "devices/<int:pk>/vlan-sync/",
        DeviceVLANTableView.as_view(),
        name="device_vlan_sync",
    ),
    path(
        "<str:object_type>/<int:object_id>/sync-vlans/",
        SyncVLANsView.as_view(),
        name="sync_selected_vlans",
    ),
    # Add Device to LibreNMS URLs
    path(
        "add-device/<int:object_id>/",
        AddDeviceToLibreNMSView.as_view(),
        name="add_device_to_librenms",
    ),
    # Site > location sync URLs
    path(
        "site-location-comparison/",
        SyncSiteLocationView.as_view(),
        name="site_location_sync",
    ),
    path(
        "create-librenms-location/<int:pk>/",
        SyncSiteLocationView.as_view(),
        name="create_librenms_location",
    ),
    path(
        "update-librenms-location/<int:pk>/",
        SyncSiteLocationView.as_view(),
        name="update_librenms_location",
    ),
    # Update device location URLs
    path(
        "devices/<int:pk>/update-location/",
        UpdateDeviceLocationView.as_view(),
        name="update_device_location",
    ),
    # Update device field URLs (name, serial, device type, platform)
    path(
        "devices/<int:pk>/update-name/",
        UpdateDeviceNameView.as_view(),
        name="update_device_name",
    ),
    path(
        "devices/<int:pk>/update-serial/",
        UpdateDeviceSerialView.as_view(),
        name="update_device_serial",
    ),
    path(
        "devices/<int:pk>/update-device-type/",
        UpdateDeviceTypeView.as_view(),
        name="update_device_type",
    ),
    path(
        "devices/<int:pk>/update-platform/",
        UpdateDevicePlatformView.as_view(),
        name="update_device_platform",
    ),
    path(
        "devices/<int:pk>/create-and-assign-platform/",
        CreateAndAssignPlatformView.as_view(),
        name="create_and_assign_platform",
    ),
    path(
        "devices/<int:pk>/assign-vc-serial/",
        AssignVCSerialView.as_view(),
        name="assign_vc_serial",
    ),
    path(
        "devices/<int:pk>/remove-server-mapping/",
        RemoveServerMappingView.as_view(),
        name="remove_server_mapping",
    ),
    path(
        "devices/<int:pk>/convert-legacy-id/",
        ConvertLegacyLibreNMSIdView.as_view(),
        name="convert_legacy_librenms_id",
    ),
    path(
        "device-status/",
        DeviceStatusListView.as_view(),
        name="device_status_list",
    ),
    path(
        "librenms-import/",
        LibreNMSImportView.as_view(),
        name="librenms_import",
    ),
    path(
        "device-import/bulk/",
        BulkImportDevicesView.as_view(),
        name="bulk_import_devices",
    ),
    path(
        "device-import/bulk/confirm/",
        BulkImportConfirmView.as_view(),
        name="bulk_import_confirm",
    ),
    path(
        "device-import/validation/<str:device_id>/",
        DeviceValidationDetailsView.as_view(),
        name="device_validation_details",
    ),
    path(
        "device-import/vc-details/<str:device_id>/",
        DeviceVCDetailsView.as_view(),
        name="device_vc_details",
    ),
    path(
        "device-import/role-update/<str:device_id>/",
        DeviceRoleUpdateView.as_view(),
        name="device_role_update",
    ),
    path(
        "device-import/cluster-update/<str:device_id>/",
        DeviceClusterUpdateView.as_view(),
        name="device_cluster_update",
    ),
    path(
        "device-import/rack-update/<str:device_id>/",
        DeviceRackUpdateView.as_view(),
        name="device_rack_update",
    ),
    path(
        "device-import/conflict-action/<str:device_id>/",
        DeviceConflictActionView.as_view(),
        name="device_conflict_action",
    ),
    path(
        "save-user-pref/",
        SaveUserPrefView.as_view(),
        name="save_user_pref",
    ),
    path(
        "vm-status/",
        VMStatusListView.as_view(),
        name="vm_status_list",
    ),
    # Settings URL
    path(
        "settings/",
        LibreNMSSettingsView.as_view(),
        name="settings",
    ),
    # Test LibreNMS connection endpoint
    path(
        "settings/test-connection/",
        TestLibreNMSConnectionView.as_view(),
        name="test_connection",
    ),
    # Interface type mapping URLs
    path(
        "interface-type-mappings/",
        InterfaceTypeMappingListView.as_view(),
        name="interfacetypemapping_list",
    ),
    path(
        "interface-type-mappings/<int:pk>/",
        InterfaceTypeMappingView.as_view(),
        name="interfacetypemapping_detail",
    ),
    path(
        "interface-type-mappings/add/",
        InterfaceTypeMappingCreateView.as_view(),
        name="interfacetypemapping_add",
    ),
    path(
        "interface-type-mappings/import/",
        InterfaceTypeMappingBulkImportView.as_view(),
        name="interfacetypemapping_bulk_import",
    ),
    path(
        "interface-type-mappings/<int:pk>/delete/",
        InterfaceTypeMappingDeleteView.as_view(),
        name="interfacetypemapping_delete",
    ),
    path(
        "interface-type-mappings/<int:pk>/edit/",
        InterfaceTypeMappingEditView.as_view(),
        name="interfacetypemapping_edit",
    ),
    path(
        "interface-type-mappings/<int:pk>/changelog/",
        InterfaceTypeMappingChangeLogView.as_view(),
        name="interfacetypemapping_changelog",
        kwargs={"model": InterfaceTypeMapping},
    ),
    path(
        "interface-type-mappings/delete/",
        InterfaceTypeMappingBulkDeleteView.as_view(),
        name="interfacetypemapping_bulk_delete",
    ),
    path("api/", include("netbox_librenms_plugin.api.urls")),
]
