"""
Platform URL Configuration
"""
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import (
    TenantViewSet,
    PlatformUserViewSet,
    TenantInvitationViewSet,
    SubscriptionPlanViewSet,
    PlatformSettingsView,
    GeneralSettingsView,
    StripeKeysView,
    StripeValidateView,
    StripeWebhooksView,
    StripeWebhookDetailView,
    StripeWebhookRotateSecretView,
    OAuthSettingsView,
    PlatformEmailAddressViewSet,
)

app_name = 'platform'

router = DefaultRouter()
router.register(r'businesses', TenantViewSet, basename='business')
router.register(r'users', PlatformUserViewSet, basename='user')
router.register(r'tenant-invitations', TenantInvitationViewSet, basename='tenant-invitation')
router.register(r'subscription-plans', SubscriptionPlanViewSet, basename='subscription-plan')
router.register(r'email-addresses', PlatformEmailAddressViewSet, basename='email-address')

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

    # Platform settings endpoints
    path('settings/', PlatformSettingsView.as_view(), name='settings'),
    path('settings/general/', GeneralSettingsView.as_view(), name='general-settings'),
    path('settings/stripe/keys/', StripeKeysView.as_view(), name='stripe-keys'),
    path('settings/stripe/validate/', StripeValidateView.as_view(), name='stripe-validate'),
    path('settings/oauth/', OAuthSettingsView.as_view(), name='oauth-settings'),

    # Stripe webhook management
    path('settings/stripe/webhooks/', StripeWebhooksView.as_view(), name='stripe-webhooks'),
    path('settings/stripe/webhooks/<str:webhook_id>/', StripeWebhookDetailView.as_view(), name='stripe-webhook-detail'),
    path('settings/stripe/webhooks/<str:webhook_id>/rotate-secret/', StripeWebhookRotateSecretView.as_view(), name='stripe-webhook-rotate-secret'),

    # Public endpoints for tenant invitations
    path(
        'tenant-invitations/token/<str:token>/',
        TenantInvitationViewSet.as_view({'get': 'retrieve_by_token'}),
        name='tenant-invitation-retrieve-by-token'
    ),
    path(
        'tenant-invitations/token/<str:token>/accept/',
        TenantInvitationViewSet.as_view({'post': 'accept'}),
        name='tenant-invitation-accept'
    ),
]
