from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import SymbolViewSet, FormulaViewSet, FormulaCategoryViewSet

# 🔧 Router z obsługą lookup_field='code'
class LookupByCodeRouter(DefaultRouter):
    def get_lookup_regex(self, viewset, lookup_prefix=''):
        if hasattr(viewset, 'lookup_field') and viewset.lookup_field == 'code':
            return r'(?P<code>[^/.]+)'
        return super().get_lookup_regex(viewset, lookup_prefix)

router = LookupByCodeRouter()
router.register(r'symbols', SymbolViewSet, basename='symbol')
router.register(r'formulas', FormulaViewSet, basename='formula')
router.register(r'formulascategories', FormulaCategoryViewSet, basename='category')

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