from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import ServiceBrokerViewSet

app_name = "broker"


class ServiceBrokerRouter(DefaultRouter):
    def get_method_map(self, viewset, method_map):
        result = super().get_method_map(viewset, method_map)

        # Add methods for service instance operations
        if hasattr(viewset, "provision_instance"):
            result.update({"put": "provision_instance"})
        if hasattr(viewset, "get_instance"):
            result.update({"get": "get_instance"})
        if hasattr(viewset, "update_instance"):
            result.update({"patch": "update_instance"})

        return result


router = ServiceBrokerRouter(trailing_slash=False)
router.register("v2", ServiceBrokerViewSet, basename="broker")

urlpatterns = [
    path("", include(router.urls)),
]
