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

from apps.party_hub.models import OpenItem, RetentionSchedule
from apps.party_hub.views import (
    CollectionActivityViewSet,
    CombinedPartyAnalyticsView,
    CreditorsAdvancesView,
    CreditorsAllocationsView,
    CreditorsDashboardView,
    CreditorsInvoicesView,
    CreditorsPaymentsView,
    CreditorsSuppliersView,
    CustomerProfileViewSet,
    DebtorsAdvancesView,
    DebtorsAllocationsView,
    DebtorsDashboardView,
    DebtorsInvoicesView,
    DebtorsReceiptsView,
    DebtorsWriteOffView,
    HubAgingView,
    HubAnalyticsView,
    PartyAdvanceAdjustmentView,
    PartyDisputeViewSet,
    PartyGroupViewSet,
    PartyLedgerDetailView,
    PartyOutstandingDetailView,
    PartyReconciliationControlView,
    PartyReconciliationExceptionsView,
    PartyReconciliationRunView,
    PartyStatementViewSet,
    PaymentProposalViewSet,
    RetentionListView,
    RetentionReleaseView,
)

router = DefaultRouter()
router.register("debtors/customers", CustomerProfileViewSet, basename="debtor-customer")
router.register("debtors/collections", CollectionActivityViewSet, basename="debtor-collection")
router.register("debtors/statements", PartyStatementViewSet, basename="debtor-statement")
router.register("creditors/payment-proposals", PaymentProposalViewSet, basename="creditor-proposal")
router.register("creditors/statements", PartyStatementViewSet, basename="creditor-statement")
router.register("party-groups", PartyGroupViewSet, basename="party-group")
router.register("party-disputes", PartyDisputeViewSet, basename="party-dispute")

urlpatterns = [
    path("", include(router.urls)),
    # Sundry Debtors Hub (AR)
    path("debtors/dashboard/", DebtorsDashboardView.as_view(), name="debtors-dashboard"),
    path("debtors/invoices/", DebtorsInvoicesView.as_view(), name="debtors-invoices"),
    path("debtors/receipts/", DebtorsReceiptsView.as_view(), name="debtors-receipts"),
    path("debtors/allocations/", DebtorsAllocationsView.as_view(), name="debtors-allocations"),
    path("debtors/write-offs/", DebtorsWriteOffView.as_view(), name="debtors-writeoffs"),
    path("debtors/advances/", DebtorsAdvancesView.as_view(), name="debtors-advances"),
    path("debtors/advance-adjustments/", PartyAdvanceAdjustmentView.as_view(), name="debtors-advance-adjustments"),
    path("debtors/retention/", RetentionListView.as_view(), {"direction": RetentionSchedule.Direction.RECEIVABLE}, name="debtors-retention"),
    path("debtors/retention/<uuid:pk>/release/", RetentionReleaseView.as_view(), name="debtors-retention-release"),
    path("debtors/aging/", HubAgingView.as_view(), {"hub_side": OpenItem.HubSide.RECEIVABLE}, name="debtors-aging"),
    path("debtors/analytics/", HubAnalyticsView.as_view(), {"hub_side": OpenItem.HubSide.RECEIVABLE}, name="debtors-analytics"),
    path("debtors/<uuid:party_id>/ledger/", PartyLedgerDetailView.as_view(), name="debtor-ledger"),
    path("debtors/<uuid:party_id>/outstanding/", PartyOutstandingDetailView.as_view(), name="debtor-outstanding"),
    # Sundry Creditors Hub (AP)
    path("creditors/dashboard/", CreditorsDashboardView.as_view(), name="creditors-dashboard"),
    path("creditors/suppliers/", CreditorsSuppliersView.as_view(), name="creditors-suppliers"),
    path("creditors/invoices/", CreditorsInvoicesView.as_view(), name="creditors-invoices"),
    path("creditors/payments/", CreditorsPaymentsView.as_view(), name="creditors-payments"),
    path("creditors/allocations/", CreditorsAllocationsView.as_view(), name="creditors-allocations"),
    path("creditors/advances/", CreditorsAdvancesView.as_view(), name="creditors-advances"),
    path("creditors/advance-adjustments/", PartyAdvanceAdjustmentView.as_view(), name="creditors-advance-adjustments"),
    path("creditors/retention/", RetentionListView.as_view(), {"direction": RetentionSchedule.Direction.PAYABLE}, name="creditors-retention"),
    path("creditors/retention/<uuid:pk>/release/", RetentionReleaseView.as_view(), name="creditors-retention-release"),
    path("creditors/aging/", HubAgingView.as_view(), {"hub_side": OpenItem.HubSide.PAYABLE}, name="creditors-aging"),
    path("creditors/analytics/", HubAnalyticsView.as_view(), {"hub_side": OpenItem.HubSide.PAYABLE}, name="creditors-analytics"),
    path("creditors/<uuid:party_id>/ledger/", PartyLedgerDetailView.as_view(), name="creditor-ledger"),
    path("creditors/<uuid:party_id>/outstanding/", PartyOutstandingDetailView.as_view(), name="creditor-outstanding"),
    # Reconciliation & Combined Analytics
    path("party-reconciliation/control-accounts/", PartyReconciliationControlView.as_view(), name="party-reconcile-controls"),
    path("party-reconciliation/run/", PartyReconciliationRunView.as_view(), name="party-reconcile-run"),
    path("party-reconciliation/exceptions/", PartyReconciliationExceptionsView.as_view(), name="party-reconcile-exceptions"),
    path("party-analytics/summary/", CombinedPartyAnalyticsView.as_view(), name="party-analytics-summary"),
]

