from django.apps import apps
from django.urls import include, path
from wbcore.routers import WBCoreRouter

from wbcommission import viewsets

router = WBCoreRouter()

router.register(
    r"rebatemarginalitytable",
    viewsets.RebateProductMarginalityViewSet,
    basename="rebatemarginalitytable",
)
router.register(
    r"rebatetable",
    viewsets.RebatePandasView,
    basename="rebatetable",
)
router.register(
    r"rebate",
    viewsets.RebateModelViewSet,
    basename="rebate",
)
router.register(
    r"commissiontype",
    viewsets.CommissionTypeModelViewSet,
    basename="commissiontype",
)
router.register(
    r"commissiontyperepresentation",
    viewsets.CommissionTypeRepresentationModelViewSet,
    basename="commissiontyperepresentation",
)
router.register(
    r"commissionrepresentation",
    viewsets.CommissionRepresentationModelViewSet,
    basename="commissionrepresentation",
)
router.register(
    r"commissionrule",
    viewsets.CommissionRuleCommissionModelViewSet,
    basename="commissionrule",
)
commission_type_account_router = WBCoreRouter()
commission_type_account_router.register(
    "commission", viewsets.CommissionModelViewSet, basename="type-account-commission"
)

commission_router = WBCoreRouter()
commission_router.register("rule", viewsets.CommissionRuleCommissionModelViewSet, basename="commission-rule")


if apps.is_installed("wbportfolio"):
    from wbportfolio.viewsets.transactions.claim import ClaimAPIModelViewSet

    router.register(r"claim-api", ClaimAPIModelViewSet, basename="claim-api")

urlpatterns = [
    path("", include(router.urls)),
    path("type/<int:commission_type_id>/account/<int:account_id>/", include(commission_type_account_router.urls)),
    path("commission/<int:commission_id>/", include(commission_router.urls)),
]
